
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/stats.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:25:44 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Stats &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../_static/sympy-notailtext-favicon.ico"/>
    <link href="stats.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Tensor" href="tensor/index.html" />
    <link rel="prev" title="Solveset" href="solvers/solveset.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tensor/index.html" title="Tensor"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="solvers/solveset.html" title="Solveset"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Stats</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.stats">
<span id="stats"></span><h1>Stats<a class="headerlink" href="#module-sympy.stats" title="Permalink to this headline">¶</a></h1>
<p>SymPy statistics module</p>
<p>Introduces a random variable type into the SymPy language.</p>
<p>Random variables may be declared using prebuilt functions such as
Normal, Exponential, Coin, Die, etc…  or built with functions like FiniteRV.</p>
<p>Queries on random expressions can be made using the functions</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 46%" />
<col style="width: 54%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p>Expression</p></td>
<td><p>Meaning</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">P(condition)</span></code></p></td>
<td><p>Probability</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">E(expression)</span></code></p></td>
<td><p>Expected value</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">H(expression)</span></code></p></td>
<td><p>Entropy</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">variance(expression)</span></code></p></td>
<td><p>Variance</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">density(expression)</span></code></p></td>
<td><p>Probability Density Function</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">sample(expression)</span></code></p></td>
<td><p>Produce a realization</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">where(condition)</span></code></p></td>
<td><p>Where the condition is true</p></td>
</tr>
</tbody>
</table>
<section id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span><span class="p">,</span> <span class="n">Die</span><span class="p">,</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">simplify</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span> <span class="c1"># Define two six sided dice</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># Declare a Normal random variable with mean 0, std 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span><span class="o">&gt;</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># Probability X is greater than 3</span>
<span class="go">1/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="o">+</span><span class="n">Y</span><span class="p">)</span> <span class="c1"># Expectation of the sum of two dice</span>
<span class="go">7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="o">+</span><span class="n">Y</span><span class="p">)</span> <span class="c1"># Variance of the sum of two dice</span>
<span class="go">35/6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">P</span><span class="p">(</span><span class="n">Z</span><span class="o">&gt;</span><span class="mi">1</span><span class="p">))</span> <span class="c1"># Probability of Z being greater than 1</span>
<span class="go">1/2 - erf(sqrt(2)/2)/2</span>
</pre></div>
</div>
<p>One could also create custom distribution and define custom random variables
as follows:</p>
<ol class="arabic simple">
<li><p>If you want to create a Continuous Random Variable:</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ContinuousRV</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">exp</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Interval</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pdf</span> <span class="o">=</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="p">)</span> <span class="c1"># pdf of the Continuous Distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">ContinuousRV</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">pdf</span><span class="p">,</span> <span class="nb">set</span><span class="o">=</span><span class="n">Interval</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">Z</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Z</span> <span class="o">&gt;</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">exp(-5)</span>
</pre></div>
</div>
<p>1.1 To create an instance of Continuous Distribution:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ContinuousDistributionHandmade</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Lambda</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span> <span class="o">=</span> <span class="n">ContinuousDistributionHandmade</span><span class="p">(</span><span class="n">Lambda</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">pdf</span><span class="p">),</span> <span class="nb">set</span><span class="o">=</span><span class="n">Interval</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">exp(-x)</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><p>If you want to create a Discrete Random Variable:</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">DiscreteRV</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pdf</span> <span class="o">=</span> <span class="n">p</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">p</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">DiscreteRV</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">pdf</span><span class="p">,</span> <span class="nb">set</span><span class="o">=</span><span class="n">S</span><span class="o">.</span><span class="n">Naturals</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">D</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">D</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">1/8</span>
</pre></div>
</div>
<p>2.1 To create an instance of Discrete Distribution:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">DiscreteDistributionHandmade</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Lambda</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span> <span class="o">=</span> <span class="n">DiscreteDistributionHandmade</span><span class="p">(</span><span class="n">Lambda</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">pdf</span><span class="p">),</span> <span class="nb">set</span><span class="o">=</span><span class="n">S</span><span class="o">.</span><span class="n">Naturals</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">2**(1 - x)/2</span>
</pre></div>
</div>
<ol class="arabic simple" start="3">
<li><p>If you want to create a Finite Random Variable:</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">FiniteRV</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Rational</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pmf</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">:</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="mi">2</span><span class="p">:</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="mi">3</span><span class="p">:</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="mi">4</span><span class="p">:</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">FiniteRV</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">pmf</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">29/12</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">1/4</span>
</pre></div>
</div>
<p>3.1 To create an instance of Finite Distribution:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">FiniteDistributionHandmade</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span> <span class="o">=</span> <span class="n">FiniteDistributionHandmade</span><span class="p">(</span><span class="n">pmf</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span><span class="o">.</span><span class="n">pmf</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Lambda(x, Piecewise((1/3, Eq(x, 1)), (1/6, Eq(x, 2)), (1/4, Eq(x, 3) | Eq(x, 4)), (0, True)))</span>
</pre></div>
</div>
</section>
<section id="random-variable-types">
<h2>Random Variable Types<a class="headerlink" href="#random-variable-types" title="Permalink to this headline">¶</a></h2>
<section id="finite-types">
<h3>Finite Types<a class="headerlink" href="#finite-types" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.DiscreteUniform">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">DiscreteUniform</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">items</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L154-L191"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteUniform" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable representing a uniform distribution over
the input set.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>items: list/tuple</strong></p>
<blockquote>
<div><p>Items over which Uniform distribution is to be made</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">DiscreteUniform</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">DiscreteUniform</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b c&#39;</span><span class="p">))</span> <span class="c1"># equally likely over a, b, c</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{a: 1/3, b: 1/3, c: 1/3}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">DiscreteUniform</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)))</span> <span class="c1"># distribution over a range</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{0: 1/5, 1: 1/5, 2: 1/5, 3: 1/5, 4: 1/5}</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r747"><span class="brackets"><a class="fn-backref" href="#id1">R747</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Discrete_uniform_distribution">https://en.wikipedia.org/wiki/Discrete_uniform_distribution</a></p>
</dd>
<dt class="label" id="r748"><span class="brackets"><a class="fn-backref" href="#id2">R748</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/DiscreteUniformDistribution.html">http://mathworld.wolfram.com/DiscreteUniformDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Die">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Die</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sides</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L228-L265"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Die" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable representing a fair die.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sides: Integer</strong></p>
<blockquote>
<div><p>Represents the number of sides of the Die, by default is 6</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Die</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D6</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;D6&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span> <span class="c1"># Six sided Die</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">D6</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{1: 1/6, 2: 1/6, 3: 1/6, 4: 1/6, 5: 1/6, 6: 1/6}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D4</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;D4&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> <span class="c1"># Four sided Die</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">D4</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{1: 1/4, 2: 1/4, 3: 1/4, 4: 1/4}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dn</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;Dn&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span> <span class="c1"># n sided Die</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">Dn</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">Density(DieDistribution(n))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">Dn</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">{1: 1/4, 2: 1/4, 3: 1/4, 4: 1/4}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Bernoulli">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Bernoulli</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">succ</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fail</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L290-L331"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Bernoulli" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable representing a Bernoulli process.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>p</strong> : Rational number between 0 and 1</p>
<blockquote>
<div><p>Represents probability of success</p>
</div></blockquote>
<p><strong>succ</strong> : Integer/symbol/string</p>
<blockquote>
<div><p>Represents event of success</p>
</div></blockquote>
<p><strong>fail</strong> : Integer/symbol/string</p>
<blockquote>
<div><p>Represents event of failure</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Bernoulli</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Bernoulli</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">)</span> <span class="c1"># 1-0 Bernoulli variable, probability = 3/4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{0: 1/4, 1: 3/4}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Bernoulli</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">,</span> <span class="s1">&#39;Heads&#39;</span><span class="p">,</span> <span class="s1">&#39;Tails&#39;</span><span class="p">)</span> <span class="c1"># A fair coin toss</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{Heads: 1/2, Tails: 1/2}</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r749"><span class="brackets"><a class="fn-backref" href="#id3">R749</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Bernoulli_distribution">https://en.wikipedia.org/wiki/Bernoulli_distribution</a></p>
</dd>
<dt class="label" id="r750"><span class="brackets"><a class="fn-backref" href="#id4">R750</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BernoulliDistribution.html">http://mathworld.wolfram.com/BernoulliDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Coin">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Coin</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span> <span class="pre">/</span> <span class="pre">2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L334-L374"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Coin" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable representing a Coin toss.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>p</strong> : Rational Numeber between 0 and 1</p>
<blockquote>
<div><p>Represents probability of getting “Heads”, by default is Half</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Coin</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Rational</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Coin</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">)</span> <span class="c1"># A fair coin toss</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">C</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{H: 1/2, T: 1/2}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C2</span> <span class="o">=</span> <span class="n">Coin</span><span class="p">(</span><span class="s1">&#39;C2&#39;</span><span class="p">,</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span> <span class="c1"># An unfair coin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">C2</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{H: 3/5, T: 2/5}</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.Binomial" title="sympy.stats.Binomial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.stats.Binomial</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r751"><span class="brackets"><a class="fn-backref" href="#id5">R751</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Coin_flipping">https://en.wikipedia.org/wiki/Coin_flipping</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Binomial">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Binomial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">succ</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fail</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L423-L470"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Binomial" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable representing a binomial distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n</strong> : Positive Integer</p>
<blockquote>
<div><p>Represents number of trials</p>
</div></blockquote>
<p><strong>p</strong> : Rational Number between 0 and 1</p>
<blockquote>
<div><p>Represents probability of success</p>
</div></blockquote>
<p><strong>succ</strong> : Integer/symbol/string</p>
<blockquote>
<div><p>Represents event of success, by default is 1</p>
</div></blockquote>
<p><strong>fail</strong> : Integer/symbol/string</p>
<blockquote>
<div><p>Represents event of failure, by default is 0</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Binomial</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Binomial</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">)</span> <span class="c1"># Four &quot;coin flips&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{0: 1/16, 1: 1/4, 2: 3/8, 3: 1/4, 4: 1/16}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;p&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Binomial</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">)</span> <span class="c1"># n &quot;coin flips&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">Density(BinomialDistribution(n, 1/2, 1, 0))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">{0: 1/16, 1: 1/4, 2: 3/8, 3: 1/4, 4: 1/16}</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r752"><span class="brackets"><a class="fn-backref" href="#id6">R752</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Binomial_distribution">https://en.wikipedia.org/wiki/Binomial_distribution</a></p>
</dd>
<dt class="label" id="r753"><span class="brackets"><a class="fn-backref" href="#id7">R753</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BinomialDistribution.html">http://mathworld.wolfram.com/BinomialDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.BetaBinomial">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">BetaBinomial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L510-L544"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.BetaBinomial" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable representing a Beta-binomial distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n</strong> : Positive Integer</p>
<blockquote>
<div><p>Represents number of trials</p>
</div></blockquote>
<p><strong>alpha</strong> : Real positive number</p>
<p><strong>beta</strong> : Real positive number</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">BetaBinomial</span><span class="p">,</span> <span class="n">density</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">BetaBinomial</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{0: 1/3, 1: 2*beta(2, 2), 2: 1/3}</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r754"><span class="brackets"><a class="fn-backref" href="#id8">R754</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Beta-binomial_distribution">https://en.wikipedia.org/wiki/Beta-binomial_distribution</a></p>
</dd>
<dt class="label" id="r755"><span class="brackets"><a class="fn-backref" href="#id9">R755</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BetaBinomialDistribution.html">http://mathworld.wolfram.com/BetaBinomialDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Hypergeometric">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Hypergeometric</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">N</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L583-L619"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Hypergeometric" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable representing a hypergeometric distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>N</strong> : Positive Integer</p>
<blockquote>
<div><p>Represents finite population of size N.</p>
</div></blockquote>
<p><strong>m</strong> : Positive Integer</p>
<blockquote>
<div><p>Represents number of trials with required feature.</p>
</div></blockquote>
<p><strong>n</strong> : Positive Integer</p>
<blockquote>
<div><p>Represents numbers of draws.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Hypergeometric</span><span class="p">,</span> <span class="n">density</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Hypergeometric</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> <span class="c1"># 10 marbles, 5 white (success), 3 draws</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{0: 1/12, 1: 5/12, 2: 5/12, 3: 1/12}</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r756"><span class="brackets"><a class="fn-backref" href="#id10">R756</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Hypergeometric_distribution">https://en.wikipedia.org/wiki/Hypergeometric_distribution</a></p>
</dd>
<dt class="label" id="r757"><span class="brackets"><a class="fn-backref" href="#id11">R757</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/HypergeometricDistribution.html">http://mathworld.wolfram.com/HypergeometricDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.FiniteRV">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">FiniteRV</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">density</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L76-L113"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.FiniteRV" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable given a dict representing the density.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>name</strong> : Symbol</p>
<blockquote>
<div><p>Represents name of the random variable.</p>
</div></blockquote>
<p><strong>density: A dict</strong></p>
<blockquote>
<div><p>Dictionary conatining the pdf of finite distribution</p>
</div></blockquote>
<p><strong>check</strong> : bool</p>
<blockquote>
<div><p>If True, it will check whether the given density
integrates to 1 over the given set. If False, it
will not perform this check. Default is False.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">FiniteRV</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mf">.1</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mf">.2</span><span class="p">,</span> <span class="mi">2</span><span class="p">:</span> <span class="mf">.3</span><span class="p">,</span> <span class="mi">3</span><span class="p">:</span> <span class="mf">.4</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">FiniteRV</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">density</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">2.00000000000000</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span> <span class="o">&gt;=</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">0.700000000000000</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Rademacher">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Rademacher</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv_types.py#L633-L662"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Rademacher" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Finite Random Variable representing a Rademacher distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Rademacher</span><span class="p">,</span> <span class="n">density</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Rademacher</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{-1: 1/2, 1: 1/2}</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.Bernoulli" title="sympy.stats.Bernoulli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.stats.Bernoulli</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r758"><span class="brackets"><a class="fn-backref" href="#id12">R758</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Rademacher_distribution">https://en.wikipedia.org/wiki/Rademacher_distribution</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="discrete-types">
<h3>Discrete Types<a class="headerlink" href="#discrete-types" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Geometric">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Geometric</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/drv_types.py#L208-L257"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Geometric" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a discrete random variable with a Geometric distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>p: A probability between 0 and 1</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Geometric distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(k) := p (1 - p)^{k - 1}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Geometric</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">S</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">One</span> <span class="o">/</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Geometric</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">(4/5)**(z - 1)/5</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">5</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">20</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r759"><span class="brackets"><a class="fn-backref" href="#id13">R759</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Geometric_distribution">https://en.wikipedia.org/wiki/Geometric_distribution</a></p>
</dd>
<dt class="label" id="r760"><span class="brackets"><a class="fn-backref" href="#id14">R760</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/GeometricDistribution.html">http://mathworld.wolfram.com/GeometricDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Hermite">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Hermite</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/drv_types.py#L293-L345"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Hermite" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a discrete random variable with a Hermite distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a1: A Positive number greater than equal to 0.</strong></p>
<p><strong>a2: A Positive number greater than equal to 0.</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Hermite distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x):= e^{-a_1 -a_2}\sum_{j=0}^{\left \lfloor x/2 \right \rfloor}
            \frac{a_{1}^{x-2j}a_{2}^{j}}{(x-2j)!j!}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Hermite</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a1</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a1&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a2</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a2&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">H</span> <span class="o">=</span> <span class="n">Hermite</span><span class="p">(</span><span class="s2">&quot;H&quot;</span><span class="p">,</span> <span class="n">a1</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">H</span><span class="p">)(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">33*exp(-9)/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">H</span><span class="p">)</span>
<span class="go">13</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">H</span><span class="p">)</span>
<span class="go">21</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r761"><span class="brackets"><a class="fn-backref" href="#id15">R761</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Hermite_distribution">https://en.wikipedia.org/wiki/Hermite_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Poisson">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Poisson</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/drv_types.py#L531-L580"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Poisson" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a discrete random variable with a Poisson distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>lamda: Positive number, a rate</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Poisson distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(k) := \frac{\lambda^{k} e^{- \lambda}}{k!}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Poisson</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rate</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;lambda&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Poisson</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">lambda**z*exp(-lambda)/factorial(z)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">lambda</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">lambda</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r762"><span class="brackets"><a class="fn-backref" href="#id16">R762</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Poisson_distribution">https://en.wikipedia.org/wiki/Poisson_distribution</a></p>
</dd>
<dt class="label" id="r763"><span class="brackets"><a class="fn-backref" href="#id17">R763</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/PoissonDistribution.html">http://mathworld.wolfram.com/PoissonDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Logarithmic">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Logarithmic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/drv_types.py#L373-L422"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Logarithmic" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a discrete random variable with a Logarithmic distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>p: A value between 0 and 1</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Logarithmic distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(k) := \frac{-p^k}{k \ln{(1 - p)}}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Logarithmic</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">S</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">One</span> <span class="o">/</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Logarithmic</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">-1/(5**z*z*log(4/5))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">-1/(-4*log(5) + 8*log(2))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">-1/((-4*log(5) + 8*log(2))*(-2*log(5) + 4*log(2))) + 1/(-64*log(2)*log(5) + 64*log(2)**2 + 16*log(5)**2) - 10/(-32*log(5) + 64*log(2))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r764"><span class="brackets"><a class="fn-backref" href="#id18">R764</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Logarithmic_distribution">https://en.wikipedia.org/wiki/Logarithmic_distribution</a></p>
</dd>
<dt class="label" id="r765"><span class="brackets"><a class="fn-backref" href="#id19">R765</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/LogarithmicDistribution.html">http://mathworld.wolfram.com/LogarithmicDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.NegativeBinomial">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">NegativeBinomial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">r</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/drv_types.py#L455-L506"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.NegativeBinomial" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a discrete random variable with a Negative Binomial distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>r: A positive value</strong></p>
<p><strong>p: A value between 0 and 1</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Negative Binomial distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(k) := \binom{k + r - 1}{k} (1 - p)^r p^k\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">NegativeBinomial</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">S</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">One</span> <span class="o">/</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">NegativeBinomial</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">1024*binomial(z + 4, z)/(3125*5**z)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">5/4</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">25/16</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r766"><span class="brackets"><a class="fn-backref" href="#id20">R766</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Negative_binomial_distribution">https://en.wikipedia.org/wiki/Negative_binomial_distribution</a></p>
</dd>
<dt class="label" id="r767"><span class="brackets"><a class="fn-backref" href="#id21">R767</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/NegativeBinomialDistribution.html">http://mathworld.wolfram.com/NegativeBinomialDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Skellam">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Skellam</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/drv_types.py#L615-L671"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Skellam" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a discrete random variable with a Skellam distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu1: A non-negative value</strong></p>
<p><strong>mu2: A non-negative value</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The Skellam is the distribution of the difference N1 - N2
of two statistically independent random variables N1 and N2
each Poisson-distributed with respective expected values mu1 and mu2.</p>
<p>The density of the Skellam distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(k) := e^{-(\mu_1+\mu_2)}(\frac{\mu_1}{\mu_2})^{k/2}I_k(2\sqrt{\mu_1\mu_2})\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Skellam</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu1</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu1&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu2</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu2&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Skellam</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu1</span><span class="p">,</span> <span class="n">mu2</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">),</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">     z</span>
<span class="go">     -</span>
<span class="go">     2</span>
<span class="go">/mu1\   -mu1 - mu2        /       _____   _____\</span>
<span class="go">|---| *e          *besseli\z, 2*\/ mu1 *\/ mu2 /</span>
<span class="go">\mu2/</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">mu1 - mu2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">mu1 + mu2</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r768"><span class="brackets"><a class="fn-backref" href="#id22">R768</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Skellam_distribution">https://en.wikipedia.org/wiki/Skellam_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.YuleSimon">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">YuleSimon</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rho</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/drv_types.py#L701-L749"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.YuleSimon" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a discrete random variable with a Yule-Simon distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rho: A positive value</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Yule-Simon distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(k) := \rho B(k, \rho + 1)\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">YuleSimon</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">YuleSimon</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">5*beta(z, 6)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">5/4</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">25/48</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r769"><span class="brackets"><a class="fn-backref" href="#id23">R769</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Yule–Simon_distribution">https://en.wikipedia.org/wiki/Yule%E2%80%93Simon_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Zeta">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Zeta</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">s</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/drv_types.py#L774-L822"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Zeta" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a discrete random variable with a Zeta distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>s: A value greater than 1</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Zeta distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(k) := \frac{1}{k^s \zeta{(s)}}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Zeta</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Zeta</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">1/(z**5*zeta(5))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">pi**4/(90*zeta(5))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">-pi**8/(8100*zeta(5)**2) + zeta(3)/zeta(5)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r770"><span class="brackets"><a class="fn-backref" href="#id24">R770</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Zeta_distribution">https://en.wikipedia.org/wiki/Zeta_distribution</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="continuous-types">
<h3>Continuous Types<a class="headerlink" href="#continuous-types" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Arcsin">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Arcsin</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L239-L289"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Arcsin" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with an arcsin distribution.</p>
<p>The density of the arcsin distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{\pi\sqrt{(x-a)(b-x)}}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in (a,b)\)</span>. It must hold that <span class="math notranslate nohighlight">\(-\infty &lt; a &lt; b &lt; \infty\)</span>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, the left interval boundary</p>
<p><strong>b</strong> : Real number, the right interval boundary</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Arcsin</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Arcsin</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">1/(pi*sqrt((-a + z)*(b - z)))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((0, a &gt; z),</span>
<span class="go">        (2*asin(sqrt((-a + z)/(-a + b)))/pi, b &gt;= z),</span>
<span class="go">        (1, True))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r771"><span class="brackets"><a class="fn-backref" href="#id25">R771</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Arcsine_distribution">https://en.wikipedia.org/wiki/Arcsine_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Benini">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Benini</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L317-L377"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Benini" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with a Benini distribution.</p>
<p>The density of the Benini distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := e^{-\alpha\log{\frac{x}{\sigma}}
        -\beta\log^2\left[{\frac{x}{\sigma}}\right]}
        \left(\frac{\alpha}{x}+\frac{2\beta\log{\frac{x}{\sigma}}}{x}\right)\]</div>
<p>This is a heavy-tailed distribution and is also known as the log-Rayleigh
distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha</strong> : Real number, <span class="math notranslate nohighlight">\(\alpha &gt; 0\)</span>, a shape</p>
<p><strong>beta</strong> : Real number, <span class="math notranslate nohighlight">\(\beta &gt; 0\)</span>, a shape</p>
<p><strong>sigma</strong> : Real number, <span class="math notranslate nohighlight">\(\sigma &gt; 0\)</span>, a scale</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Benini</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">alpha</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;alpha&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">beta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;beta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;sigma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Benini</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">/                  /  z  \\             /  z  \            2/  z  \</span>
<span class="go">|        2*beta*log|-----||  - alpha*log|-----| - beta*log  |-----|</span>
<span class="go">|alpha             \sigma/|             \sigma/             \sigma/</span>
<span class="go">|----- + -----------------|*e</span>
<span class="go">\  z             z        /</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((1 - exp(-alpha*log(z/sigma) - beta*log(z/sigma)**2), sigma &lt;= z),</span>
<span class="go">        (0, True))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r772"><span class="brackets"><a class="fn-backref" href="#id26">R772</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Benini_distribution">https://en.wikipedia.org/wiki/Benini_distribution</a></p>
</dd>
<dt class="label" id="r773"><span class="brackets"><a class="fn-backref" href="#id27">R773</a></span></dt>
<dd><p><a class="reference external" href="http://reference.wolfram.com/legacy/v8/ref/BeniniDistribution.html">http://reference.wolfram.com/legacy/v8/ref/BeniniDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Beta">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Beta</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L404-L459"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Beta" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with a Beta distribution.</p>
<p>The density of the Beta distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{x^{\alpha-1}(1-x)^{\beta-1}} {\mathrm{B}(\alpha,\beta)}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [0,1]\)</span>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha</strong> : Real number, <span class="math notranslate nohighlight">\(\alpha &gt; 0\)</span>, a shape</p>
<p><strong>beta</strong> : Real number, <span class="math notranslate nohighlight">\(\beta &gt; 0\)</span>, a shape</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Beta</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span><span class="p">,</span> <span class="n">pprint</span><span class="p">,</span> <span class="n">factor</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">alpha</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;alpha&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">beta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;beta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Beta</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go"> alpha - 1        beta - 1</span>
<span class="go">z         *(1 - z)</span>
<span class="go">--------------------------</span>
<span class="go">      B(alpha, beta)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">alpha/(alpha + beta)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span><span class="p">(</span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)))</span>
<span class="go">alpha*beta/((alpha + beta)**2*(alpha + beta + 1))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r774"><span class="brackets"><a class="fn-backref" href="#id28">R774</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Beta_distribution">https://en.wikipedia.org/wiki/Beta_distribution</a></p>
</dd>
<dt class="label" id="r775"><span class="brackets"><a class="fn-backref" href="#id29">R775</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BetaDistribution.html">http://mathworld.wolfram.com/BetaDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.BetaNoncentral">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">BetaNoncentral</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L482-L549"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.BetaNoncentral" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with a Type I Noncentral Beta distribution.</p>
<p>The density of the Noncentral Beta distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \sum_{k=0}^\infty e^{-\lambda/2}\frac{(\lambda/2)^k}{k!}
        \frac{x^{\alpha+k-1}(1-x)^{\beta-1}}{\mathrm{B}(\alpha+k,\beta)}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [0,1]\)</span>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha</strong> : Real number, <span class="math notranslate nohighlight">\(\alpha &gt; 0\)</span>, a shape</p>
<p><strong>beta</strong> : Real number, <span class="math notranslate nohighlight">\(\beta &gt; 0\)</span>, a shape</p>
<p><strong>lamda: Real number, `lambda &gt;= 0`, noncentrality parameter</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">BetaNoncentral</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">alpha</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;alpha&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">beta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;beta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lamda</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;lamda&quot;</span><span class="p">,</span> <span class="n">nonnegative</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">BetaNoncentral</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">lamda</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">  oo</span>
<span class="go">_____</span>
<span class="go">\    `</span>
<span class="go"> \                                              -lamda</span>
<span class="go">  \                          k                  -------</span>
<span class="go">   \    k + alpha - 1 /lamda\         beta - 1     2</span>
<span class="go">    )  z             *|-----| *(1 - z)        *e</span>
<span class="go">   /                  \  2  /</span>
<span class="go">  /    ------------------------------------------------</span>
<span class="go"> /                  B(k + alpha, beta)*k!</span>
<span class="go">/____,</span>
<span class="go">k = 0</span>
</pre></div>
</div>
<p>Compute cdf with specific ‘x’, ‘alpha’, ‘beta’ and ‘lamda’ values as follows :
&gt;&gt;&gt; cdf(BetaNoncentral(“x”, 1, 1, 1), evaluate=False)(2).doit()
2*exp(1/2)</p>
<p>The argument evaluate=False prevents an attempt at evaluation
of the sum for general x, before the argument 2 is passed.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r776"><span class="brackets"><a class="fn-backref" href="#id30">R776</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Noncentral_beta_distribution">https://en.wikipedia.org/wiki/Noncentral_beta_distribution</a></p>
</dd>
<dt class="label" id="r777"><span class="brackets"><a class="fn-backref" href="#id31">R777</a></span></dt>
<dd><p><a class="reference external" href="https://reference.wolfram.com/language/ref/NoncentralBetaDistribution.html">https://reference.wolfram.com/language/ref/NoncentralBetaDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.BetaPrime">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">BetaPrime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L570-L619"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.BetaPrime" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Beta prime distribution.</p>
<p>The density of the Beta prime distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{x^{\alpha-1} (1+x)^{-\alpha -\beta}}{B(\alpha,\beta)}\]</div>
<p>with <span class="math notranslate nohighlight">\(x &gt; 0\)</span>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha</strong> : Real number, <span class="math notranslate nohighlight">\(\alpha &gt; 0\)</span>, a shape</p>
<p><strong>beta</strong> : Real number, <span class="math notranslate nohighlight">\(\beta &gt; 0\)</span>, a shape</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">BetaPrime</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">alpha</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;alpha&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">beta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;beta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">BetaPrime</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go"> alpha - 1        -alpha - beta</span>
<span class="go">z         *(z + 1)</span>
<span class="go">-------------------------------</span>
<span class="go">         B(alpha, beta)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r778"><span class="brackets"><a class="fn-backref" href="#id32">R778</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Beta_prime_distribution">https://en.wikipedia.org/wiki/Beta_prime_distribution</a></p>
</dd>
<dt class="label" id="r779"><span class="brackets"><a class="fn-backref" href="#id33">R779</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/BetaPrimeDistribution.html">http://mathworld.wolfram.com/BetaPrimeDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.BoundedPareto">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">BoundedPareto</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">left</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">right</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L642-L687"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.BoundedPareto" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Bounded Pareto distribution.</p>
<p>The density of the Bounded Pareto distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\alpha L^{\alpha}x^{-\alpha-1}}{1-(\frac{L}{H})^{\alpha}}\]</div>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha</strong> : Real Number, <span class="math notranslate nohighlight">\(alpha &gt; 0\)</span></p>
<blockquote>
<div><p>Shape parameter</p>
</div></blockquote>
<p><strong>left</strong> : Real Number, <span class="math notranslate nohighlight">\(left &gt; 0\)</span></p>
<blockquote>
<div><p>Location parameter</p>
</div></blockquote>
<p><strong>right</strong> : Real Number, <span class="math notranslate nohighlight">\(right &gt; left\)</span></p>
<blockquote>
<div><p>Location parameter</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">BoundedPareto</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="p">,</span> <span class="n">H</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;L, H&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">BoundedPareto</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">L</span><span class="p">,</span> <span class="n">H</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">2*L**2/(x**3*(1 - L**2/H**2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Piecewise((-H**2*L**2/(x**2*(H**2 - L**2)) + H**2/(H**2 - L**2), L &lt;= x), (0, True))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">2*H*L/(H + L)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r780"><span class="brackets"><a class="fn-backref" href="#id34">R780</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Pareto_distribution#Bounded_Pareto_distribution">https://en.wikipedia.org/wiki/Pareto_distribution#Bounded_Pareto_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Cauchy">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Cauchy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gamma</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L719-L762"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Cauchy" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Cauchy distribution.</p>
<p>The density of the Cauchy distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{\pi \gamma [1 + {(\frac{x-x_0}{\gamma})}^2]}\]</div>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>x0</strong> : Real number, the location</p>
<p><strong>gamma</strong> : Real number, <span class="math notranslate nohighlight">\(\gamma &gt; 0\)</span>, a scale</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Cauchy</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x0</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x0&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gamma</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;gamma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Cauchy</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">x0</span><span class="p">,</span> <span class="n">gamma</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">1/(pi*gamma*(1 + (-x0 + z)**2/gamma**2))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r781"><span class="brackets"><a class="fn-backref" href="#id35">R781</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Cauchy_distribution">https://en.wikipedia.org/wiki/Cauchy_distribution</a></p>
</dd>
<dt class="label" id="r782"><span class="brackets"><a class="fn-backref" href="#id36">R782</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/CauchyDistribution.html">http://mathworld.wolfram.com/CauchyDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Chi">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Chi</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L797-L843"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Chi" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Chi distribution.</p>
<p>The density of the Chi distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{2^{1-k/2}x^{k-1}e^{-x^2/2}}{\Gamma(k/2)}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \geq 0\)</span>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>k</strong> : Positive integer, The number of degrees of freedom</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Chi</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Chi</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">2**(1 - k/2)*z**(k - 1)*exp(-z**2/2)/gamma(k/2)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">sqrt(2)*gamma(k/2 + 1/2)/gamma(k/2)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r783"><span class="brackets"><a class="fn-backref" href="#id37">R783</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Chi_distribution">https://en.wikipedia.org/wiki/Chi_distribution</a></p>
</dd>
<dt class="label" id="r784"><span class="brackets"><a class="fn-backref" href="#id38">R784</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/ChiDistribution.html">http://mathworld.wolfram.com/ChiDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.ChiNoncentral">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">ChiNoncentral</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L864-L914"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.ChiNoncentral" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a non-central Chi distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>k</strong> : A positive Integer, <span class="math notranslate nohighlight">\(k &gt; 0\)</span></p>
<blockquote>
<div><p>The number of degrees of freedom.</p>
</div></blockquote>
<p><strong>lambda</strong> : Real number, <span class="math notranslate nohighlight">\(\lambda &gt; 0\)</span></p>
<blockquote>
<div><p>Shift parameter.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the non-central Chi distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{e^{-(x^2+\lambda^2)/2} x^k\lambda}
        {(\lambda x)^{k/2}} I_{k/2-1}(\lambda x)\]</div>
<p>with <span class="math notranslate nohighlight">\(x \geq 0\)</span>. Here, <span class="math notranslate nohighlight">\(I_\nu (x)\)</span> is the
<a class="reference internal" href="functions/special.html#besseli"><span class="std std-ref">modified Bessel function of the first kind</span></a>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ChiNoncentral</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;l&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">ChiNoncentral</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">l*z**k*exp(-l**2/2 - z**2/2)*besseli(k/2 - 1, l*z)/(l*z)**(k/2)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r785"><span class="brackets"><a class="fn-backref" href="#id39">R785</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Noncentral_chi_distribution">https://en.wikipedia.org/wiki/Noncentral_chi_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.ChiSquared">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">ChiSquared</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L948-L1004"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.ChiSquared" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Chi-squared distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>k</strong> : Positive integer</p>
<blockquote>
<div><p>The number of degrees of freedom.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Chi-squared distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{2^{\frac{k}{2}}\Gamma\left(\frac{k}{2}\right)}
        x^{\frac{k}{2}-1} e^{-\frac{x}{2}}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \geq 0\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ChiSquared</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span><span class="p">,</span> <span class="n">moment</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">ChiSquared</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">z**(k/2 - 1)*exp(-z/2)/(2**(k/2)*gamma(k/2))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">k</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">2*k</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">moment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">k**3 + 6*k**2 + 8*k</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r786"><span class="brackets"><a class="fn-backref" href="#id40">R786</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Chi_squared_distribution">https://en.wikipedia.org/wiki/Chi_squared_distribution</a></p>
</dd>
<dt class="label" id="r787"><span class="brackets"><a class="fn-backref" href="#id41">R787</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">http://mathworld.wolfram.com/Chi-SquaredDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Dagum">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Dagum</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1030-L1087"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Dagum" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Dagum distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>p</strong> : Real number</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">p</span> <span class="pre">&gt;</span> <span class="pre">0</span></code>, a shape.</p>
</div></blockquote>
<p><strong>a</strong> : Real number</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">&gt;</span> <span class="pre">0</span></code>, a shape.</p>
</div></blockquote>
<p><strong>b</strong> : Real number</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">b</span> <span class="pre">&gt;</span> <span class="pre">0</span></code>, a scale.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Dagum distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{a p}{x} \left( \frac{\left(\tfrac{x}{b}\right)^{a p}}
        {\left(\left(\tfrac{x}{b}\right)^a + 1 \right)^{p+1}} \right)\]</div>
<p>with <span class="math notranslate nohighlight">\(x &gt; 0\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Dagum</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;p&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Dagum</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">a*p*(z/b)**(a*p)*((z/b)**a + 1)**(-p - 1)/z</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise(((1 + (z/b)**(-a))**(-p), z &gt;= 0), (0, True))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r788"><span class="brackets"><a class="fn-backref" href="#id42">R788</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Dagum_distribution">https://en.wikipedia.org/wiki/Dagum_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Erlang">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Erlang</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1093-L1160"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Erlang" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with an Erlang distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>k</strong> : Positive integer</p>
<p><strong>l</strong> : Real number, <span class="math notranslate nohighlight">\(\lambda &gt; 0\)</span>, the rate</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Erlang distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\lambda^k x^{k-1} e^{-\lambda x}}{(k-1)!}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [0,\infty]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Erlang</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;l&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Erlang</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go"> k  k - 1  -l*z</span>
<span class="go">l *z     *e</span>
<span class="go">---------------</span>
<span class="go">    Gamma(k)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">/lowergamma(k, l*z)</span>
<span class="go">|------------------  for z &gt; 0</span>
<span class="go">&lt;     Gamma(k)</span>
<span class="go">|</span>
<span class="go">\        0           otherwise</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">k/l</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">k/l**2</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r789"><span class="brackets"><a class="fn-backref" href="#id43">R789</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Erlang_distribution">https://en.wikipedia.org/wiki/Erlang_distribution</a></p>
</dd>
<dt class="label" id="r790"><span class="brackets"><a class="fn-backref" href="#id44">R790</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/ErlangDistribution.html">http://mathworld.wolfram.com/ErlangDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.ExGaussian">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">ExGaussian</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mean</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">std</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rate</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1207-L1277"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.ExGaussian" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with an Exponentially modified
Gaussian (EMG) distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : A Real number, the mean of Gaussian component</p>
<p><strong>std: A positive Real number,</strong></p>
<blockquote>
<div><dl class="field-list simple">
<dt class="field-odd">math</dt>
<dd class="field-odd"><p><span class="math notranslate nohighlight">\(\sigma^2 &gt; 0\)</span> the variance of Gaussian component</p>
</dd>
</dl>
</div></blockquote>
<p><strong>lambda: A positive Real number,</strong></p>
<blockquote>
<div><dl class="field-list simple">
<dt class="field-odd">math</dt>
<dd class="field-odd"><p><span class="math notranslate nohighlight">\(\lambda &gt; 0\)</span> the rate of Exponential component</p>
</dd>
</dl>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the exponentially modified Gaussian distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\lambda}{2}e^{\frac{\lambda}{2}(2\mu+\lambda\sigma^2-2x)}
    \text{erfc}(\frac{\mu + \lambda\sigma^2 - x}{\sqrt{2}\sigma})\]</div>
<p>with <span class="math notranslate nohighlight">\(x &gt; 0\)</span>. Note that the expected value is <span class="math notranslate nohighlight">\(1/\lambda\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ExGaussian</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">variance</span><span class="p">,</span> <span class="n">skewness</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mean</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">std</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;sigma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rate</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;lamda&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">ExGaussian</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mean</span><span class="p">,</span> <span class="n">std</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">),</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">             /           2             \</span>
<span class="go">       lamda*\lamda*sigma  + 2*mu - 2*z/</span>
<span class="go">       ---------------------------------     /  ___ /           2         \\</span>
<span class="go">                       2                     |\/ 2 *\lamda*sigma  + mu - z/|</span>
<span class="go">lamda*e                                 *erfc|-----------------------------|</span>
<span class="go">                                             \           2*sigma           /</span>
<span class="go">----------------------------------------------------------------------------</span>
<span class="go">                                     2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">-(erf(sqrt(2)*(-lamda**2*sigma**2 + lamda*(-mu + z))/(2*lamda*sigma))/2 + 1/2)*exp(lamda**2*sigma**2/2 - lamda*(-mu + z)) + erf(sqrt(2)*(-mu + z)/(2*sigma))/2 + 1/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">(lamda*mu + 1)/lamda</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">sigma**2 + lamda**(-2)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">skewness</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">2/(lamda**2*sigma**2 + 1)**(3/2)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r791"><span class="brackets"><a class="fn-backref" href="#id45">R791</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Exponentially_modified_Gaussian_distribution">https://en.wikipedia.org/wiki/Exponentially_modified_Gaussian_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Exponential">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Exponential</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rate</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1313-L1386"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Exponential" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with an Exponential distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rate</strong> : A positive Real number, <span class="math notranslate nohighlight">\(\lambda &gt; 0\)</span>, the rate (or inverse scale/inverse mean)</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the exponential distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \lambda \exp(-\lambda x)\]</div>
<p>with <span class="math notranslate nohighlight">\(x &gt; 0\)</span>. Note that the expected value is <span class="math notranslate nohighlight">\(1/\lambda\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Exponential</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">variance</span><span class="p">,</span> <span class="n">std</span><span class="p">,</span> <span class="n">skewness</span><span class="p">,</span> <span class="n">quantile</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">l</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;lambda&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;p&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">lambda*exp(-lambda*z)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((1 - exp(-lambda*z), z &gt;= 0), (0, True))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">quantile</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">p</span><span class="p">)</span>
<span class="go">-log(1 - p)/lambda</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">1/lambda</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">lambda**(-2)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">skewness</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">10*exp(-10*z)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">1/10</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">std</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">1/10</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r792"><span class="brackets"><a class="fn-backref" href="#id46">R792</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Exponential_distribution">https://en.wikipedia.org/wiki/Exponential_distribution</a></p>
</dd>
<dt class="label" id="r793"><span class="brackets"><a class="fn-backref" href="#id47">R793</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/ExponentialDistribution.html">http://mathworld.wolfram.com/ExponentialDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.FDistribution">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">FDistribution</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1505-L1563"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.FDistribution" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a F distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>d1</strong> : <span class="math notranslate nohighlight">\(d_1 &gt; 0\)</span>, where d_1 is the degrees of freedom (n_1 - 1)</p>
<p><strong>d2</strong> : <span class="math notranslate nohighlight">\(d_2 &gt; 0\)</span>, where d_2 is the degrees of freedom (n_2 - 1)</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the F distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\sqrt{\frac{(d_1 x)^{d_1} d_2^{d_2}}
        {(d_1 x + d_2)^{d_1 + d_2}}}}
        {x \mathrm{B} \left(\frac{d_1}{2}, \frac{d_2}{2}\right)}\]</div>
<p>with <span class="math notranslate nohighlight">\(x &gt; 0\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">FDistribution</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">d1</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;d1&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d2</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;d2&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">FDistribution</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">d1</span><span class="p">,</span> <span class="n">d2</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">  d2</span>
<span class="go">  --    ______________________________</span>
<span class="go">  2    /       d1            -d1 - d2</span>
<span class="go">d2  *\/  (d1*z)  *(d1*z + d2)</span>
<span class="go">--------------------------------------</span>
<span class="go">                /d1  d2\</span>
<span class="go">             z*B|--, --|</span>
<span class="go">                \2   2 /</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r794"><span class="brackets"><a class="fn-backref" href="#id48">R794</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/F-distribution">https://en.wikipedia.org/wiki/F-distribution</a></p>
</dd>
<dt class="label" id="r795"><span class="brackets"><a class="fn-backref" href="#id49">R795</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/F-Distribution.html">http://mathworld.wolfram.com/F-Distribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.FisherZ">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">FisherZ</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1583-L1644"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.FisherZ" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with an Fisher’s Z distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>d1</strong> : <code class="docutils literal notranslate"><span class="pre">d_1</span> <span class="pre">&gt;</span> <span class="pre">0</span></code></p>
<blockquote>
<div><p>Degree of freedom.</p>
</div></blockquote>
<p><strong>d2</strong> : <code class="docutils literal notranslate"><span class="pre">d_2</span> <span class="pre">&gt;</span> <span class="pre">0</span></code></p>
<blockquote>
<div><p>Degree of freedom.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Fisher’s Z distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{2d_1^{d_1/2} d_2^{d_2/2}} {\mathrm{B}(d_1/2, d_2/2)}
        \frac{e^{d_1z}}{\left(d_1e^{2z}+d_2\right)^{\left(d_1+d_2\right)/2}}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">FisherZ</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">d1</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;d1&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d2</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;d2&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">FisherZ</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">d1</span><span class="p">,</span> <span class="n">d2</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">                            d1   d2</span>
<span class="go">    d1   d2               - -- - --</span>
<span class="go">    --   --                 2    2</span>
<span class="go">    2    2  /    2*z     \           d1*z</span>
<span class="go">2*d1  *d2  *\d1*e    + d2/         *e</span>
<span class="go">-----------------------------------------</span>
<span class="go">                 /d1  d2\</span>
<span class="go">                B|--, --|</span>
<span class="go">                 \2   2 /</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r796"><span class="brackets"><a class="fn-backref" href="#id50">R796</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Fisher%27s_z-distribution">https://en.wikipedia.org/wiki/Fisher%27s_z-distribution</a></p>
</dd>
<dt class="label" id="r797"><span class="brackets"><a class="fn-backref" href="#id51">R797</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/Fishersz-Distribution.html">http://mathworld.wolfram.com/Fishersz-Distribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Frechet">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Frechet</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">s</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1672-L1725"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Frechet" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Frechet distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, <span class="math notranslate nohighlight">\(a \in \left(0, \infty\right)\)</span> the shape</p>
<p><strong>s</strong> : Real number, <span class="math notranslate nohighlight">\(s \in \left(0, \infty\right)\)</span> the scale</p>
<p><strong>m</strong> : Real number, <span class="math notranslate nohighlight">\(m \in \left(-\infty, \infty\right)\)</span> the minimum</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Frechet distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\alpha}{s} \left(\frac{x-m}{s}\right)^{-1-\alpha}
         e^{-(\frac{x-m}{s})^{-\alpha}}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \geq m\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Frechet</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;s&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;m&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Frechet</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">a*((-m + z)/s)**(-a - 1)*exp(-1/((-m + z)/s)**a)/s</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((exp(-1/((-m + z)/s)**a), m &lt;= z), (0, True))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r798"><span class="brackets"><a class="fn-backref" href="#id52">R798</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Fréchet_distribution">https://en.wikipedia.org/wiki/Fr%C3%A9chet_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Gamma">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Gamma</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">theta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1758-L1831"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Gamma" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Gamma distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>k</strong> : Real number, <code class="docutils literal notranslate"><span class="pre">k</span> <span class="pre">&gt;</span> <span class="pre">0</span></code>, a shape</p>
<p><strong>theta</strong> : Real number, <span class="math notranslate nohighlight">\(\theta &gt; 0\)</span>, a scale</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Gamma distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{\Gamma(k) \theta^k} x^{k - 1} e^{-\frac{x}{\theta}}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [0,1]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Gamma</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">theta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;theta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Gamma</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">theta</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">                  -z</span>
<span class="go">                -----</span>
<span class="go">     -k  k - 1  theta</span>
<span class="go">theta  *z     *e</span>
<span class="go">---------------------</span>
<span class="go">       Gamma(k)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">meijerg</span><span class="o">=</span><span class="kc">True</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">/            /     z  \</span>
<span class="go">|k*lowergamma|k, -----|</span>
<span class="go">|            \   theta/</span>
<span class="go">&lt;----------------------  for z &gt;= 0</span>
<span class="go">|     Gamma(k + 1)</span>
<span class="go">|</span>
<span class="go">\          0             otherwise</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">k*theta</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> <span class="o">=</span> <span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">V</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">       2</span>
<span class="go">k*theta</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r799"><span class="brackets"><a class="fn-backref" href="#id53">R799</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Gamma_distribution">https://en.wikipedia.org/wiki/Gamma_distribution</a></p>
</dd>
<dt class="label" id="r800"><span class="brackets"><a class="fn-backref" href="#id54">R800</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/GammaDistribution.html">http://mathworld.wolfram.com/GammaDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.GammaInverse">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">GammaInverse</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1864-L1922"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.GammaInverse" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with an inverse Gamma distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, <span class="math notranslate nohighlight">\(a &gt; 0\)</span> a shape</p>
<p><strong>b</strong> : Real number, <span class="math notranslate nohighlight">\(b &gt; 0\)</span> a scale</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the inverse Gamma distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\beta^\alpha}{\Gamma(\alpha)} x^{-\alpha - 1}
        \exp\left(\frac{-\beta}{x}\right)\]</div>
<p>with <span class="math notranslate nohighlight">\(x &gt; 0\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">GammaInverse</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">GammaInverse</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">            -b</span>
<span class="go">            ---</span>
<span class="go"> a  -a - 1   z</span>
<span class="go">b *z      *e</span>
<span class="go">---------------</span>
<span class="go">   Gamma(a)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((uppergamma(a, b/z)/gamma(a), z &gt; 0), (0, True))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r801"><span class="brackets"><a class="fn-backref" href="#id55">R801</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Inverse-gamma_distribution">https://en.wikipedia.org/wiki/Inverse-gamma_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Gompertz">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Gompertz</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2048-L2094"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Gompertz" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with Gompertz distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>b: Real number, ‘b &gt; 0’ a scale</strong></p>
<p><strong>eta: Real number, ‘eta &gt; 0’ a shape</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Gompertz distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := b \eta e^{b x} e^{\eta} \exp \left(-\eta e^{bx} \right)\]</div>
<p>with :math: ‘x in [0, inf)’.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Gompertz</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;eta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Gompertz</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">eta</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">b*eta*exp(eta)*exp(b*z)*exp(-eta*exp(b*z))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r802"><span class="brackets"><a class="fn-backref" href="#id56">R802</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Gompertz_distribution">https://en.wikipedia.org/wiki/Gompertz_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Gumbel">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Gumbel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">minimum</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L1962-L2021"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Gumbel" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with Gumbel distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number, ‘mu’ is a location</p>
<p><strong>beta</strong> : Real number, ‘beta &gt; 0’ is a scale</p>
<p><strong>minimum</strong> : Boolean, by default, False, set to True for enabling minimum distribution</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Gumbel distribution is given by</p>
<p>For Maximum</p>
<div class="math notranslate nohighlight">
\[f(x) := \dfrac{1}{\beta} \exp \left( -\dfrac{x-\mu}{\beta}
        - \exp \left( -\dfrac{x - \mu}{\beta} \right) \right)\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [ - \infty, \infty ]\)</span>.</p>
<p>For Minimum</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{e^{- e^{\frac{- \mu + x}{\beta}} + \frac{- \mu + x}{\beta}}}{\beta}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [ - \infty, \infty ]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Gumbel</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">beta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;beta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Gumbel</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">mu</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">exp(-exp(-(-mu + x)/beta) - (-mu + x)/beta)/beta</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">exp(-exp(-(-mu + x)/beta))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r803"><span class="brackets"><a class="fn-backref" href="#id57">R803</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/GumbelDistribution.html">http://mathworld.wolfram.com/GumbelDistribution.html</a></p>
</dd>
<dt class="label" id="r804"><span class="brackets"><a class="fn-backref" href="#id58">R804</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Gumbel_distribution">https://en.wikipedia.org/wiki/Gumbel_distribution</a></p>
</dd>
<dt class="label" id="r805"><span class="brackets"><a class="fn-backref" href="#id59">R805</a></span></dt>
<dd><p><a class="reference external" href="http://www.mathwave.com/help/easyfit/html/analyses/distributions/gumbel_max.html">http://www.mathwave.com/help/easyfit/html/analyses/distributions/gumbel_max.html</a></p>
</dd>
<dt class="label" id="r806"><span class="brackets"><a class="fn-backref" href="#id60">R806</a></span></dt>
<dd><p><a class="reference external" href="http://www.mathwave.com/help/easyfit/html/analyses/distributions/gumbel_min.html">http://www.mathwave.com/help/easyfit/html/analyses/distributions/gumbel_min.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Kumaraswamy">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Kumaraswamy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2121-L2174"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Kumaraswamy" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with a Kumaraswamy distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">&gt;</span> <span class="pre">0</span></code> a shape</p>
<p><strong>b</strong> : Real number, <code class="docutils literal notranslate"><span class="pre">b</span> <span class="pre">&gt;</span> <span class="pre">0</span></code> a shape</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Kumaraswamy distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := a b x^{a-1} (1-x^a)^{b-1}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [0,1]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Kumaraswamy</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Kumaraswamy</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">                   b - 1</span>
<span class="go">     a - 1 /     a\</span>
<span class="go">a*b*z     *\1 - z /</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((0, z &lt; 0), (1 - (1 - z**a)**b, z &lt;= 1), (1, True))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r807"><span class="brackets"><a class="fn-backref" href="#id61">R807</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Kumaraswamy_distribution">https://en.wikipedia.org/wiki/Kumaraswamy_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Laplace">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Laplace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2207-L2270"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Laplace" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Laplace distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number or a list/matrix, the location (mean) or the</p>
<blockquote>
<div><p>location vector</p>
</div></blockquote>
<p><strong>b</strong> : Real number or a positive definite matrix, representing a scale</p>
<blockquote>
<div><p>or the covariance matrix.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Laplace distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{2 b} \exp \left(-\frac{|x-\mu|}b \right)\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Laplace</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Laplace</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">exp(-Abs(mu - z)/b)/(2*b)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((exp((-mu + z)/b)/2, mu &gt; z), (1 - exp((mu - z)/b)/2, True))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">L</span> <span class="o">=</span> <span class="n">Laplace</span><span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">density</span><span class="p">(</span><span class="n">L</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go"> 5        /     ____\</span>
<span class="go">e *besselk\0, \/ 35 /</span>
<span class="go">---------------------</span>
<span class="go">          pi</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r808"><span class="brackets"><a class="fn-backref" href="#id62">R808</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Laplace_distribution">https://en.wikipedia.org/wiki/Laplace_distribution</a></p>
</dd>
<dt class="label" id="r809"><span class="brackets"><a class="fn-backref" href="#id63">R809</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/LaplaceDistribution.html">http://mathworld.wolfram.com/LaplaceDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Levy">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Levy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2303-L2349"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Levy" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Levy distribution.</p>
<p>The density of the Levy distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \sqrt(\frac{c}{2 \pi}) \frac{\exp -\frac{c}{2 (x - \mu)}}{(x - \mu)^{3/2}}\]</div>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number</p>
<blockquote>
<div><p>The location parameter.</p>
</div></blockquote>
<p><strong>c</strong> : Real number, <code class="docutils literal notranslate"><span class="pre">c</span> <span class="pre">&gt;</span> <span class="pre">0</span></code></p>
<blockquote>
<div><p>A scale parameter.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Levy</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;c&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Levy</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">sqrt(2)*sqrt(c)*exp(-c/(-2*mu + 2*z))/(2*sqrt(pi)*(-mu + z)**(3/2))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">erfc(sqrt(c)*sqrt(1/(-2*mu + 2*z)))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r810"><span class="brackets"><a class="fn-backref" href="#id64">R810</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Lévy_distribution">https://en.wikipedia.org/wiki/L%C3%A9vy_distribution</a></p>
</dd>
<dt class="label" id="r811"><span class="brackets"><a class="fn-backref" href="#id65">R811</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/LevyDistribution.html">http://mathworld.wolfram.com/LevyDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Logistic">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Logistic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">s</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2458-L2507"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Logistic" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a logistic distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number, the location (mean)</p>
<p><strong>s</strong> : Real number, <span class="math notranslate nohighlight">\(s &gt; 0\)</span> a scale</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the logistic distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{e^{-(x-\mu)/s}} {s\left(1+e^{-(x-\mu)/s}\right)^2}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Logistic</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;s&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Logistic</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">exp((mu - z)/s)/(s*(exp((mu - z)/s) + 1)**2)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">1/(exp((mu - z)/s) + 1)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r812"><span class="brackets"><a class="fn-backref" href="#id66">R812</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Logistic_distribution">https://en.wikipedia.org/wiki/Logistic_distribution</a></p>
</dd>
<dt class="label" id="r813"><span class="brackets"><a class="fn-backref" href="#id67">R813</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/LogisticDistribution.html">http://mathworld.wolfram.com/LogisticDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.LogLogistic">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">LogLogistic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2539-L2603"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.LogLogistic" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a log-logistic distribution.
The distribution is unimodal when <code class="docutils literal notranslate"><span class="pre">beta</span> <span class="pre">&gt;</span> <span class="pre">1</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha</strong> : Real number, <span class="math notranslate nohighlight">\(\alpha &gt; 0\)</span>, scale parameter and median of distribution</p>
<p><strong>beta</strong> : Real number, <span class="math notranslate nohighlight">\(\beta &gt; 0\)</span> a shape parameter</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the log-logistic distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{(\frac{\beta}{\alpha})(\frac{x}{\alpha})^{\beta - 1}}
        {(1 + (\frac{x}{\alpha})^{\beta})^2}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">LogLogistic</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">quantile</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">alpha</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;alpha&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">beta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;beta&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;p&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">LogLogistic</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">              beta - 1</span>
<span class="go">       /  z  \</span>
<span class="go">  beta*|-----|</span>
<span class="go">       \alpha/</span>
<span class="go">------------------------</span>
<span class="go">                       2</span>
<span class="go">      /       beta    \</span>
<span class="go">      |/  z  \        |</span>
<span class="go">alpha*||-----|     + 1|</span>
<span class="go">      \\alpha/        /</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">1/(1 + (z/alpha)**(-beta))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">quantile</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">p</span><span class="p">)</span>
<span class="go">alpha*(p/(1 - p))**(1/beta)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r814"><span class="brackets"><a class="fn-backref" href="#id68">R814</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Log-logistic_distribution">https://en.wikipedia.org/wiki/Log-logistic_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.LogNormal">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">LogNormal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mean</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">std</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2718-L2784"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.LogNormal" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a log-normal distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number</p>
<blockquote>
<div><p>The log-scale.</p>
</div></blockquote>
<p><strong>sigma</strong> : Real number</p>
<blockquote>
<div><p>A shape. (<span class="math notranslate nohighlight">\(\sigma^2 &gt; 0\)</span>)</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the log-normal distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{x\sqrt{2\pi\sigma^2}}
        e^{-\frac{\left(\ln x-\mu\right)^2}{2\sigma^2}}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \geq 0\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">LogNormal</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;sigma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">LogNormal</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">                      2</span>
<span class="go">       -(-mu + log(z))</span>
<span class="go">       -----------------</span>
<span class="go">                  2</span>
<span class="go">  ___      2*sigma</span>
<span class="go">\/ 2 *e</span>
<span class="go">------------------------</span>
<span class="go">        ____</span>
<span class="go">    2*\/ pi *sigma*z</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">LogNormal</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># Mean 0, standard deviation 1</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">sqrt(2)*exp(-log(z)**2/2)/(2*sqrt(pi)*z)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r815"><span class="brackets"><a class="fn-backref" href="#id69">R815</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Lognormal">https://en.wikipedia.org/wiki/Lognormal</a></p>
</dd>
<dt class="label" id="r816"><span class="brackets"><a class="fn-backref" href="#id70">R816</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/LogNormalDistribution.html">http://mathworld.wolfram.com/LogNormalDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Lomax">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Lomax</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2804-L2852"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Lomax" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Lomax distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha</strong> : Real Number, <span class="math notranslate nohighlight">\(alpha &gt; 0\)</span></p>
<blockquote>
<div><p>Shape parameter</p>
</div></blockquote>
<p><strong>lamda</strong> : Real Number, <span class="math notranslate nohighlight">\(lamda &gt; 0\)</span></p>
<blockquote>
<div><p>Scale parameter</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Lomax distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\alpha}{\lambda}\left[1+\frac{x}{\lambda}\right]^{-(\alpha+1)}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Lomax</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">l</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a, l&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Lomax</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">a*(1 + x/l)**(-a - 1)/l</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Piecewise((1 - 1/(1 + x/l)**a, x &gt;= 0), (0, True))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Lomax</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">l</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r817"><span class="brackets"><a class="fn-backref" href="#id71">R817</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Lomax_distribution">https://en.wikipedia.org/wiki/Lomax_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Maxwell">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Maxwell</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2875-L2929"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Maxwell" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Maxwell distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, <span class="math notranslate nohighlight">\(a &gt; 0\)</span></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Maxwell distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \sqrt{\frac{2}{\pi}} \frac{x^2 e^{-x^2/(2a^2)}}{a^3}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \geq 0\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Maxwell</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Maxwell</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">sqrt(2)*z**2*exp(-z**2/(2*a**2))/(sqrt(pi)*a**3)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">2*sqrt(2)*a/sqrt(pi)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">a**2*(-8 + 3*pi)/pi</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r818"><span class="brackets"><a class="fn-backref" href="#id72">R818</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Maxwell_distribution">https://en.wikipedia.org/wiki/Maxwell_distribution</a></p>
</dd>
<dt class="label" id="r819"><span class="brackets"><a class="fn-backref" href="#id73">R819</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/MaxwellDistribution.html">http://mathworld.wolfram.com/MaxwellDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Moyal">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Moyal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L2960-L3009"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Moyal" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Moyal distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number</p>
<blockquote>
<div><p>Location parameter</p>
</div></blockquote>
<p><strong>sigma</strong> : Real positive number</p>
<blockquote>
<div><p>Scale parameter</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Moyal distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\exp-\frac{1}{2}\exp-\frac{x-\mu}{\sigma}-\frac{x-\mu}{2\sigma}}{\sqrt{2\pi}\sigma}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in \mathbb{R}\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Moyal</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;sigma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Moyal</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">sqrt(2)*exp(-exp((mu - z)/sigma)/2 - (-mu + z)/(2*sigma))/(2*sqrt(pi)*sigma)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">))</span>
<span class="go">1 - erf(sqrt(2)*exp((mu - z)/(2*sigma))/2)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r820"><span class="brackets"><a class="fn-backref" href="#id74">R820</a></span></dt>
<dd><p><a class="reference external" href="https://reference.wolfram.com/language/ref/MoyalDistribution.html">https://reference.wolfram.com/language/ref/MoyalDistribution.html</a></p>
</dd>
<dt class="label" id="r821"><span class="brackets"><a class="fn-backref" href="#id75">R821</a></span></dt>
<dd><p><a class="reference external" href="http://www.stat.rice.edu/~dobelman/textfiles/DistributionsHandbook.pdf">http://www.stat.rice.edu/~dobelman/textfiles/DistributionsHandbook.pdf</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Nakagami">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Nakagami</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">omega</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3035-L3105"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Nakagami" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Nakagami distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number, <span class="math notranslate nohighlight">\(\mu \geq \frac{1}{2}\)</span> a shape</p>
<p><strong>omega</strong> : Real number, <span class="math notranslate nohighlight">\(\omega &gt; 0\)</span>, the spread</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Nakagami distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{2\mu^\mu}{\Gamma(\mu)\omega^\mu} x^{2\mu-1}
        \exp\left(-\frac{\mu}{\omega}x^2 \right)\]</div>
<p>with <span class="math notranslate nohighlight">\(x &gt; 0\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Nakagami</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">omega</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;omega&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Nakagami</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">omega</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">                                2</span>
<span class="go">                           -mu*z</span>
<span class="go">                           -------</span>
<span class="go">    mu      -mu  2*mu - 1  omega</span>
<span class="go">2*mu  *omega   *z        *e</span>
<span class="go">----------------------------------</span>
<span class="go">            Gamma(mu)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">sqrt(mu)*sqrt(omega)*gamma(mu + 1/2)/gamma(mu + 1)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> <span class="o">=</span> <span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">V</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">                    2</span>
<span class="go">         omega*Gamma (mu + 1/2)</span>
<span class="go">omega - -----------------------</span>
<span class="go">        Gamma(mu)*Gamma(mu + 1)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((lowergamma(mu, mu*z**2/omega)/gamma(mu), z &gt; 0),</span>
<span class="go">        (0, True))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r822"><span class="brackets"><a class="fn-backref" href="#id76">R822</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Nakagami_distribution">https://en.wikipedia.org/wiki/Nakagami_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Normal">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Normal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mean</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">std</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3138-L3229"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Normal" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Normal distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number or a list representing the mean or the mean vector</p>
<p><strong>sigma</strong> : Real number or a positive definite square matrix,</p>
<blockquote>
<div><p><span class="math notranslate nohighlight">\(\sigma^2 &gt; 0\)</span> the variance</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Normal distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{\sigma\sqrt{2\pi}} e^{ -\frac{(x-\mu)^2}{2\sigma^2} }\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">std</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">skewness</span><span class="p">,</span> <span class="n">quantile</span><span class="p">,</span> <span class="n">marginal_distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;sigma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;y&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;p&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">sqrt(2)*exp(-(-mu + z)**2/(2*sigma**2))/(2*sqrt(pi)*sigma)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">simplify</span><span class="p">(</span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">))(</span><span class="n">z</span><span class="p">)</span> <span class="c1"># it needs a little more help...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">   /  ___          \</span>
<span class="go">   |\/ 2 *(-mu + z)|</span>
<span class="go">erf|---------------|</span>
<span class="go">   \    2*sigma    /   1</span>
<span class="go">-------------------- + -</span>
<span class="go">         2             2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">quantile</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">p</span><span class="p">)</span>
<span class="go">mu + sqrt(2)*sigma*erfinv(2*p - 1)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">skewness</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">0</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># Mean 0, standard deviation 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">sqrt(2)*exp(-z**2/2)/(2*sqrt(pi))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">std</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
<span class="go">2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">density</span><span class="p">(</span><span class="n">m</span><span class="p">)(</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">),</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">          2          2</span>
<span class="go">         y    y*z   z</span>
<span class="go">       - -- + --- - -- + z - 1</span>
<span class="go">  ___    3     3    3</span>
<span class="go">\/ 3 *e</span>
<span class="go">------------------------------</span>
<span class="go">             6*pi</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">marginal_distribution</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">])(</span><span class="mi">1</span><span class="p">)</span>
<span class="go"> 1/(2*sqrt(pi))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r823"><span class="brackets"><a class="fn-backref" href="#id77">R823</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Normal_distribution">https://en.wikipedia.org/wiki/Normal_distribution</a></p>
</dd>
<dt class="label" id="r824"><span class="brackets"><a class="fn-backref" href="#id78">R824</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/NormalDistributionFunction.html">http://mathworld.wolfram.com/NormalDistributionFunction.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Pareto">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Pareto</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xm</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3377-L3425"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Pareto" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with the Pareto distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>xm</strong> : Real number, <span class="math notranslate nohighlight">\(x_m &gt; 0\)</span>, a scale</p>
<p><strong>alpha</strong> : Real number, <span class="math notranslate nohighlight">\(\alpha &gt; 0\)</span>, a shape</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Pareto distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\alpha\,x_m^\alpha}{x^{\alpha+1}}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [x_m,\infty]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Pareto</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">xm</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;xm&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">beta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;beta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Pareto</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">xm</span><span class="p">,</span> <span class="n">beta</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">beta*xm**beta*z**(-beta - 1)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r825"><span class="brackets"><a class="fn-backref" href="#id79">R825</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Pareto_distribution">https://en.wikipedia.org/wiki/Pareto_distribution</a></p>
</dd>
<dt class="label" id="r826"><span class="brackets"><a class="fn-backref" href="#id80">R826</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/ParetoDistribution.html">http://mathworld.wolfram.com/ParetoDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.PowerFunction">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">PowerFunction</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3451-L3513"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.PowerFunction" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a continuous random variable with a Power Function Distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha: Positive number, `0 &lt; alpha` the shape paramater</strong></p>
<p><strong>a</strong> : Real number, <span class="math notranslate nohighlight">\(-\infty &lt; a\)</span> the left boundary</p>
<p><strong>b</strong> : Real number, <span class="math notranslate nohighlight">\(a &lt; b &lt; \infty\)</span> the right boundary</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of PowerFunction distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{{\alpha}(x - a)^{\alpha - 1}}{(b - a)^{\alpha}}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [a,b]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">PowerFunction</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">alpha</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;alpha&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">PowerFunction</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">(-2*a + 2*z)/(-a + b)**2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((a**2/(a**2 - 2*a*b + b**2) - 2*a*z/(a**2 - 2*a*b + b**2) +</span>
<span class="go">z**2/(a**2 - 2*a*b + b**2), a &lt;= z), (0, True))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">alpha</span> <span class="o">=</span> <span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="mi">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">PowerFunction</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span>
<span class="go">2/3</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span>
<span class="go">1/18</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r827"><span class="brackets"><a class="fn-backref" href="#id81">R827</a></span></dt>
<dd><p><a class="reference external" href="http://www.mathwave.com/help/easyfit/html/analyses/distributions/power_func.html">http://www.mathwave.com/help/easyfit/html/analyses/distributions/power_func.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.QuadraticU">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">QuadraticU</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3549-L3605"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.QuadraticU" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with a U-quadratic distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number</p>
<p><strong>b</strong> : Real number, <span class="math notranslate nohighlight">\(a &lt; b\)</span></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the U-quadratic distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \alpha (x-\beta)^2\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [a,b]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">QuadraticU</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">QuadraticU</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">/                2</span>
<span class="go">|   /  a   b    \</span>
<span class="go">|12*|- - - - + z|</span>
<span class="go">|   \  2   2    /</span>
<span class="go">&lt;-----------------  for And(b &gt;= z, a &lt;= z)</span>
<span class="go">|            3</span>
<span class="go">|    (-a + b)</span>
<span class="go">|</span>
<span class="go">\        0                 otherwise</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r828"><span class="brackets"><a class="fn-backref" href="#id82">R828</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/U-quadratic_distribution">https://en.wikipedia.org/wiki/U-quadratic_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.RaisedCosine">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">RaisedCosine</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">s</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3638-L3692"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.RaisedCosine" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with a raised cosine distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number</p>
<p><strong>s</strong> : Real number, <span class="math notranslate nohighlight">\(s &gt; 0\)</span></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the raised cosine distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{2s}\left(1+\cos\left(\frac{x-\mu}{s}\pi\right)\right)\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [\mu-s,\mu+s]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">RaisedCosine</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;s&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">RaisedCosine</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">/   /pi*(-mu + z)\</span>
<span class="go">|cos|------------| + 1</span>
<span class="go">|   \     s      /</span>
<span class="go">&lt;---------------------  for And(z &gt;= mu - s, z &lt;= mu + s)</span>
<span class="go">|         2*s</span>
<span class="go">|</span>
<span class="go">\          0                        otherwise</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r829"><span class="brackets"><a class="fn-backref" href="#id83">R829</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Raised_cosine_distribution">https://en.wikipedia.org/wiki/Raised_cosine_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Rayleigh">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Rayleigh</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3724-L3776"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Rayleigh" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Rayleigh distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sigma</strong> : Real number, <span class="math notranslate nohighlight">\(\sigma &gt; 0\)</span></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Rayleigh distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{x}{\sigma^2} e^{-x^2/2\sigma^2}\]</div>
<p>with <span class="math notranslate nohighlight">\(x &gt; 0\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Rayleigh</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;sigma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Rayleigh</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">z*exp(-z**2/(2*sigma**2))/sigma**2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">sqrt(2)*sqrt(pi)*sigma/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">-pi*sigma**2/2 + 2*sigma**2</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r830"><span class="brackets"><a class="fn-backref" href="#id84">R830</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Rayleigh_distribution">https://en.wikipedia.org/wiki/Rayleigh_distribution</a></p>
</dd>
<dt class="label" id="r831"><span class="brackets"><a class="fn-backref" href="#id85">R831</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/RayleighDistribution.html">http://mathworld.wolfram.com/RayleighDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Reciprocal">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Reciprocal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3799-L3833"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Reciprocal" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a continuous random variable with a reciprocal distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, <span class="math notranslate nohighlight">\(0 &lt; a\)</span></p>
<p><strong>b</strong> : Real number, <span class="math notranslate nohighlight">\(a &lt; b\)</span></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Reciprocal</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">x</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a, b, x&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">Reciprocal</span><span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">R</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">1/(x*(-log(a) + log(b)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">R</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Piecewise((log(a)/(log(a) - log(b)) - log(x)/(log(a) - log(b)), a &lt;= x), (0, True))</span>
</pre></div>
</div>
<p class="rubric">Reference</p>
<dl class="citation">
<dt class="label" id="r832"><span class="brackets">R832</span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Reciprocal_distribution">https://en.wikipedia.org/wiki/Reciprocal_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.StudentT">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">StudentT</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nu</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3927-L3989"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.StudentT" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a student’s t distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>nu</strong> : Real number, <span class="math notranslate nohighlight">\(\nu &gt; 0\)</span>, the degrees of freedom</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the student’s t distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{\Gamma \left(\frac{\nu+1}{2} \right)}
        {\sqrt{\nu\pi}\Gamma \left(\frac{\nu}{2} \right)}
        \left(1+\frac{x^2}{\nu} \right)^{-\frac{\nu+1}{2}}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">StudentT</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">nu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;nu&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">StudentT</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">nu</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">           nu   1</span>
<span class="go">         - -- - -</span>
<span class="go">           2    2</span>
<span class="go"> /     2\</span>
<span class="go"> |    z |</span>
<span class="go"> |1 + --|</span>
<span class="go"> \    nu/</span>
<span class="go">-----------------</span>
<span class="go">  ____  /     nu\</span>
<span class="go">\/ nu *B|1/2, --|</span>
<span class="go">        \     2 /</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">1/2 + z*gamma(nu/2 + 1/2)*hyper((1/2, nu/2 + 1/2), (3/2,),</span>
<span class="go">                            -z**2/nu)/(sqrt(pi)*sqrt(nu)*gamma(nu/2))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r833"><span class="brackets"><a class="fn-backref" href="#id86">R833</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Student_t-distribution">https://en.wikipedia.org/wiki/Student_t-distribution</a></p>
</dd>
<dt class="label" id="r834"><span class="brackets"><a class="fn-backref" href="#id87">R834</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/Studentst-Distribution.html">http://mathworld.wolfram.com/Studentst-Distribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.ShiftedGompertz">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">ShiftedGompertz</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3854-L3899"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.ShiftedGompertz" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Shifted Gompertz distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>b: Real number, ‘b &gt; 0’ a scale</strong></p>
<p><strong>eta: Real number, ‘eta &gt; 0’ a shape</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Shifted Gompertz distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := b e^{-b x} e^{-\eta \exp(-b x)} \left[1 + \eta(1 - e^(-bx)) \right]\]</div>
<p>with :math: ‘x in [0, inf)’.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ShiftedGompertz</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;eta&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">ShiftedGompertz</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">eta</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">b*(eta*(1 - exp(-b*x)) + 1)*exp(-b*x)*exp(-eta*exp(-b*x))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r835"><span class="brackets"><a class="fn-backref" href="#id88">R835</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Shifted_Gompertz_distribution">https://en.wikipedia.org/wiki/Shifted_Gompertz_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Trapezoidal">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Trapezoidal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L4019-L4085"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Trapezoidal" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a trapezoidal distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, <span class="math notranslate nohighlight">\(a &lt; d\)</span></p>
<p><strong>b</strong> : Real number, <span class="math notranslate nohighlight">\(a &lt;= b &lt; c\)</span></p>
<p><strong>c</strong> : Real number, <span class="math notranslate nohighlight">\(b &lt; c &lt;= d\)</span></p>
<p><strong>d</strong> : Real number</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the trapezoidal distribution is given by</p>
<div class="math notranslate nohighlight">
\[\begin{split}f(x) := \begin{cases}
          0 &amp; \mathrm{for\ } x &lt; a, \\
          \frac{2(x-a)}{(b-a)(d+c-a-b)} &amp; \mathrm{for\ } a \le x &lt; b, \\
          \frac{2}{d+c-a-b} &amp; \mathrm{for\ } b \le x &lt; c, \\
          \frac{2(d-x)}{(d-c)(d+c-a-b)} &amp; \mathrm{for\ } c \le x &lt; d, \\
          0 &amp; \mathrm{for\ } d &lt; x.
        \end{cases}\end{split}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Trapezoidal</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;c&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;d&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Trapezoidal</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">,</span><span class="n">d</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">),</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">/        -2*a + 2*z</span>
<span class="go">|-------------------------  for And(a &lt;= z, b &gt; z)</span>
<span class="go">|(-a + b)*(-a - b + c + d)</span>
<span class="go">|</span>
<span class="go">|           2</span>
<span class="go">|     --------------        for And(b &lt;= z, c &gt; z)</span>
<span class="go">&lt;     -a - b + c + d</span>
<span class="go">|</span>
<span class="go">|        2*d - 2*z</span>
<span class="go">|-------------------------  for And(d &gt;= z, c &lt;= z)</span>
<span class="go">|(-c + d)*(-a - b + c + d)</span>
<span class="go">|</span>
<span class="go">\            0                     otherwise</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r836"><span class="brackets"><a class="fn-backref" href="#id89">R836</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Trapezoidal_distribution">https://en.wikipedia.org/wiki/Trapezoidal_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Triangular">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Triangular</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L4122-L4188"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Triangular" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a triangular distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, <span class="math notranslate nohighlight">\(a \in \left(-\infty, \infty\right)\)</span></p>
<p><strong>b</strong> : Real number, <span class="math notranslate nohighlight">\(a &lt; b\)</span></p>
<p><strong>c</strong> : Real number, <span class="math notranslate nohighlight">\(a \leq c \leq b\)</span></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the triangular distribution is given by</p>
<div class="math notranslate nohighlight">
\[\begin{split}f(x) := \begin{cases}
          0 &amp; \mathrm{for\ } x &lt; a, \\
          \frac{2(x-a)}{(b-a)(c-a)} &amp; \mathrm{for\ } a \le x &lt; c, \\
          \frac{2}{b-a} &amp; \mathrm{for\ } x = c, \\
          \frac{2(b-x)}{(b-a)(b-c)} &amp; \mathrm{for\ } c &lt; x \le b, \\
          0 &amp; \mathrm{for\ } b &lt; x.
        \end{cases}\end{split}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Triangular</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;c&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Triangular</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">),</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">/    -2*a + 2*z</span>
<span class="go">|-----------------  for And(a &lt;= z, c &gt; z)</span>
<span class="go">|(-a + b)*(-a + c)</span>
<span class="go">|</span>
<span class="go">|       2</span>
<span class="go">|     ------              for c = z</span>
<span class="go">&lt;     -a + b</span>
<span class="go">|</span>
<span class="go">|   2*b - 2*z</span>
<span class="go">|----------------   for And(b &gt;= z, c &lt; z)</span>
<span class="go">|(-a + b)*(b - c)</span>
<span class="go">|</span>
<span class="go">\        0                otherwise</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r837"><span class="brackets"><a class="fn-backref" href="#id90">R837</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Triangular_distribution">https://en.wikipedia.org/wiki/Triangular_distribution</a></p>
</dd>
<dt class="label" id="r838"><span class="brackets"><a class="fn-backref" href="#id91">R838</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/TriangularDistribution.html">http://mathworld.wolfram.com/TriangularDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Uniform">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Uniform</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">left</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">right</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L4239-L4299"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Uniform" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a uniform distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a</strong> : Real number, <span class="math notranslate nohighlight">\(-\infty &lt; a\)</span> the left boundary</p>
<p><strong>b</strong> : Real number, <span class="math notranslate nohighlight">\(a &lt; b &lt; \infty\)</span> the right boundary</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the uniform distribution is given by</p>
<div class="math notranslate nohighlight">
\[\begin{split}f(x) := \begin{cases}
          \frac{1}{b - a} &amp; \text{for } x \in [a,b]  \\
          0               &amp; \text{otherwise}
        \end{cases}\end{split}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [a,b]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Uniform</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="n">negative</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Uniform</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((1/(-a + b), (b &gt;= z) &amp; (a &lt;= z)), (0, True))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((0, a &gt; z), ((-a + z)/(-a + b), b &gt;= z), (1, True))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">a/2 + b/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">a**2/12 - a*b/6 + b**2/12</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r839"><span class="brackets"><a class="fn-backref" href="#id92">R839</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)">https://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29</a></p>
</dd>
<dt class="label" id="r840"><span class="brackets"><a class="fn-backref" href="#id93">R840</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/UniformDistribution.html">http://mathworld.wolfram.com/UniformDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.UniformSum">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">UniformSum</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L4337-L4407"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.UniformSum" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with an Irwin-Hall distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n</strong> : A positive Integer, <span class="math notranslate nohighlight">\(n &gt; 0\)</span></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The probability distribution function depends on a single parameter
<span class="math notranslate nohighlight">\(n\)</span> which is an integer.</p>
<p>The density of the Irwin-Hall distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{1}{(n-1)!}\sum_{k=0}^{\left\lfloor x\right\rfloor}(-1)^k
        \binom{n}{k}(x-k)^{n-1}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">UniformSum</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">cdf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;n&quot;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">UniformSum</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">floor(z)</span>
<span class="go">  ___</span>
<span class="go">  \  `</span>
<span class="go">   \         k         n - 1 /n\</span>
<span class="go">    )    (-1) *(-k + z)     *| |</span>
<span class="go">   /                         \k/</span>
<span class="go">  /__,</span>
<span class="go"> k = 0</span>
<span class="go">--------------------------------</span>
<span class="go">            (n - 1)!</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cdf</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">Piecewise((0, z &lt; 0), (Sum((-1)**_k*(-_k + z)**n*binomial(n, _k),</span>
<span class="go">                (_k, 0, floor(z)))/factorial(n), n &gt;= z), (1, True))</span>
</pre></div>
</div>
<p>Compute cdf with specific ‘x’ and ‘n’ values as follows :
&gt;&gt;&gt; cdf(UniformSum(“x”, 5), evaluate=False)(2).doit()
9/40</p>
<p>The argument evaluate=False prevents an attempt at evaluation
of the sum for general n, before the argument 2 is passed.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r841"><span class="brackets"><a class="fn-backref" href="#id94">R841</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Uniform_sum_distribution">https://en.wikipedia.org/wiki/Uniform_sum_distribution</a></p>
</dd>
<dt class="label" id="r842"><span class="brackets"><a class="fn-backref" href="#id95">R842</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/UniformSumDistribution.html">http://mathworld.wolfram.com/UniformSumDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.VonMises">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">VonMises</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L4426-L4481"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.VonMises" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable with a von Mises distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : Real number</p>
<blockquote>
<div><p>Measure of location.</p>
</div></blockquote>
<p><strong>k</strong> : Real number</p>
<blockquote>
<div><p>Measure of concentration.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the von Mises distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac{e^{\kappa\cos(x-\mu)}}{2\pi I_0(\kappa)}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [0,2\pi]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">VonMises</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">VonMises</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">     k*cos(mu - z)</span>
<span class="go">    e</span>
<span class="go">------------------</span>
<span class="go">2*pi*besseli(0, k)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r843"><span class="brackets"><a class="fn-backref" href="#id96">R843</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Von_Mises_distribution">https://en.wikipedia.org/wiki/Von_Mises_distribution</a></p>
</dd>
<dt class="label" id="r844"><span class="brackets"><a class="fn-backref" href="#id97">R844</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/vonMisesDistribution.html">http://mathworld.wolfram.com/vonMisesDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Wald">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Wald</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mean</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L3271-L3337"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Wald" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with an Inverse Gaussian distribution.
Inverse Gaussian distribution is also known as Wald distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu :</strong></p>
<blockquote>
<div><p>Positive number representing the mean.</p>
</div></blockquote>
<p><strong>lambda :</strong></p>
<blockquote>
<div><p>Positive number representing the shape parameter.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Inverse Gaussian distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \sqrt{\frac{\lambda}{2\pi x^3}} e^{-\frac{\lambda(x-\mu)^2}{2x\mu^2}}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">GaussianInverse</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">std</span><span class="p">,</span> <span class="n">skewness</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">pprint</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lamda</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;lambda&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">GaussianInverse</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">lamda</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">                                   2</span>
<span class="go">                  -lambda*(-mu + z)</span>
<span class="go">                  -------------------</span>
<span class="go">                            2</span>
<span class="go">  ___   ________        2*mu *z</span>
<span class="go">\/ 2 *\/ lambda *e</span>
<span class="go">-------------------------------------</span>
<span class="go">                ____  3/2</span>
<span class="go">            2*\/ pi *z</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">mu</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">std</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">mu**(3/2)/sqrt(lambda)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">skewness</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">3*sqrt(mu)/sqrt(lambda)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r845"><span class="brackets"><a class="fn-backref" href="#id98">R845</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Inverse_Gaussian_distribution">https://en.wikipedia.org/wiki/Inverse_Gaussian_distribution</a></p>
</dd>
<dt class="label" id="r846"><span class="brackets"><a class="fn-backref" href="#id99">R846</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/InverseGaussianDistribution.html">http://mathworld.wolfram.com/InverseGaussianDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Weibull">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Weibull</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L4502-L4558"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Weibull" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Weibull distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>lambda</strong> : Real number, <span class="math notranslate nohighlight">\(\lambda &gt; 0\)</span> a scale</p>
<p><strong>k</strong> : Real number, <code class="docutils literal notranslate"><span class="pre">k</span> <span class="pre">&gt;</span> <span class="pre">0</span></code> a shape</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Weibull distribution is given by</p>
<div class="math notranslate nohighlight">
\[\begin{split}f(x) := \begin{cases}
          \frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}
          e^{-(x/\lambda)^{k}} &amp; x\geq0\\
          0 &amp; x&lt;0
        \end{cases}\end{split}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Weibull</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">l</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;lambda&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Weibull</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">k*(z/lambda)**(k - 1)*exp(-(z/lambda)**k)/lambda</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">lambda*gamma(1 + 1/k)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
<span class="go">lambda**2*(-gamma(1 + 1/k)**2 + gamma(1 + 2/k))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r847"><span class="brackets"><a class="fn-backref" href="#id100">R847</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Weibull_distribution">https://en.wikipedia.org/wiki/Weibull_distribution</a></p>
</dd>
<dt class="label" id="r848"><span class="brackets"><a class="fn-backref" href="#id101">R848</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/WeibullDistribution.html">http://mathworld.wolfram.com/WeibullDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.WignerSemicircle">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">WignerSemicircle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">R</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L4587-L4636"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.WignerSemicircle" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a continuous random variable with a Wigner semicircle distribution.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>R</strong> : Real number, <span class="math notranslate nohighlight">\(R &gt; 0\)</span>, the radius</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A <span class="math notranslate nohighlight">\(RandomSymbol\)</span>.</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The density of the Wigner semicircle distribution is given by</p>
<div class="math notranslate nohighlight">
\[f(x) := \frac2{\pi R^2}\,\sqrt{R^2-x^2}\]</div>
<p>with <span class="math notranslate nohighlight">\(x \in [-R,R]\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">WignerSemicircle</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;R&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">WignerSemicircle</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">R</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">z</span><span class="p">)</span>
<span class="go">2*sqrt(R**2 - z**2)/(pi*R**2)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r849"><span class="brackets"><a class="fn-backref" href="#id102">R849</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Wigner_semicircle_distribution">https://en.wikipedia.org/wiki/Wigner_semicircle_distribution</a></p>
</dd>
<dt class="label" id="r850"><span class="brackets"><a class="fn-backref" href="#id103">R850</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/WignersSemicircleLaw.html">http://mathworld.wolfram.com/WignersSemicircleLaw.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.ContinuousRV">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">ContinuousRV</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symbol</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">density</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">set</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">Interval(-</span> <span class="pre">oo,</span> <span class="pre">oo)</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv_types.py#L162-L210"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.ContinuousRV" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Continuous Random Variable given the following:</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>symbol</strong> : Symbol</p>
<blockquote>
<div><p>Represents name of the random variable.</p>
</div></blockquote>
<p><strong>density</strong> : Expression containing symbol</p>
<blockquote>
<div><p>Represents probability density function.</p>
</div></blockquote>
<p><strong>set</strong> : set/Interval</p>
<blockquote>
<div><p>Represents the region where the pdf is valid, by default is real line.</p>
</div></blockquote>
<p><strong>check</strong> : bool</p>
<blockquote>
<div><p>If True, it will check whether the given density
integrates to 1 over the given set. If False, it
will not perform this check. Default is False.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
<p>Many common continuous random variable types are already implemented.</p>
<p>This function should be necessary only very rarely.</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ContinuousRV</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">pdf</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="n">pi</span><span class="p">))</span> <span class="c1"># Normal distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">ContinuousRV</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">pdf</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">)</span>
<span class="go">1/2</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="joint-types">
<h3>Joint Types<a class="headerlink" href="#joint-types" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.JointRV">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">JointRV</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symbol</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pdf</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_set</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L81-L123"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.JointRV" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Joint Random Variable where each of its component is conitinuous,
given the following:</p>
<p>– a symbol
– a PDF in terms of indexed symbols of the symbol given
as the first argument</p>
<p>NOTE: As of now, the set for each component for a <span class="math notranslate nohighlight">\(JointRV\)</span> is
equal to the set of all integers, which can not be changed.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">exp</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">Indexed</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">JointRV</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span> <span class="o">=</span> <span class="p">(</span><span class="n">Indexed</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pdf</span> <span class="o">=</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x1</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x1</span> <span class="o">-</span> <span class="n">x2</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">2</span> <span class="o">-</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N1</span> <span class="o">=</span> <span class="n">JointRV</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">pdf</span><span class="p">)</span> <span class="c1">#Multivariate Normal distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">N1</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">exp(-2)/(2*pi)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.marginal_distribution">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">marginal_distribution</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rv</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">indices</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L33-L68"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.marginal_distribution" title="Permalink to this definition">¶</a></dt>
<dd><p>Marginal distribution function of a joint random variable.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rv: A random variable with a joint probability distribution.</strong></p>
<p><strong>indices: component indices or the indexed random symbol</strong></p>
<blockquote>
<div><p>for whom the joint distribution is to be calculated</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A Lambda expression in <span class="math notranslate nohighlight">\(sym\)</span>.</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">MultivariateNormal</span><span class="p">,</span> <span class="n">marginal_distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">MultivariateNormal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">marginal_distribution</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">])(</span><span class="mi">1</span><span class="p">)</span>
<span class="go">1/(2*sqrt(pi))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.MultivariateNormal">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">MultivariateNormal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L172-L229"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.MultivariateNormal" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a continuous random variable with Multivariate Normal
Distribution.</p>
<p>The density of the multivariate normal distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : List representing the mean or the mean vector</p>
<p><strong>sigma</strong> : Positive semidefinite square matrix</p>
<blockquote>
<div><p>Represents covariance Matrix
If <span class="math notranslate nohighlight">\(sigma\)</span> is noninvertible then only sampling is supported currently</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">MultivariateNormal</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">marginal_distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MultivariateNormal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;y z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span>
<span class="go">sqrt(3)*exp(-y**2/3 + y*z/3 + 2*y/3 - z**2/3 + 5*z/3 - 13/3)/(6*pi)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">sqrt(3)*exp(-4/3)/(6*pi)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">marginal_distribution</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span><span class="p">[</span><span class="mi">1</span><span class="p">])(</span><span class="n">y</span><span class="p">)</span>
<span class="go">exp(-(y - 4)**2/4)/(2*sqrt(pi))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">marginal_distribution</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span><span class="p">[</span><span class="mi">0</span><span class="p">])(</span><span class="n">y</span><span class="p">)</span>
<span class="go">exp(-(y - 3)**2/4)/(2*sqrt(pi))</span>
</pre></div>
</div>
<p>The example below shows that it is also possible to use
symbolic parameters to define the MultivariateNormal class.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">natural</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sg</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Sg&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;mu&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obs</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;obs&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MultivariateNormal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">Sg</span><span class="p">)</span>
</pre></div>
</div>
<p>The density of a multivariate normal can be
calculated using a matrix argument, as shown below.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">obs</span><span class="p">)</span>
<span class="go">(exp(((1/2)*mu.T - (1/2)*obs.T)*Sg**(-1)*(-mu + obs))/sqrt((2*pi)**n*Determinant(Sg)))[0, 0]</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r851"><span class="brackets"><a class="fn-backref" href="#id104">R851</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Multivariate_normal_distribution">https://en.wikipedia.org/wiki/Multivariate_normal_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.MultivariateLaplace">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">MultivariateLaplace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L266-L303"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.MultivariateLaplace" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a continuous random variable with Multivariate Laplace
Distribution.</p>
<p>The density of the multivariate Laplace distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mu</strong> : List representing the mean or the mean vector</p>
<p><strong>sigma</strong> : Positive definite square matrix</p>
<blockquote>
<div><p>Represents covariance Matrix</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">MultivariateLaplace</span><span class="p">,</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;y z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MultivariateLaplace</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span>
<span class="go">sqrt(2)*exp(y/4 + 5*z/4)*besselk(0, sqrt(15*y*(3*y/8 - z/8)/2 + 15*z*(-y/8 + 3*z/8)/2))/(4*pi)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">sqrt(2)*exp(11/4)*besselk(0, sqrt(165)/4)/(4*pi)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r852"><span class="brackets"><a class="fn-backref" href="#id105">R852</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Multivariate_Laplace_distribution">https://en.wikipedia.org/wiki/Multivariate_Laplace_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.GeneralizedMultivariateLogGamma">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">GeneralizedMultivariateLogGamma</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">syms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">v</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L652-L704"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.GeneralizedMultivariateLogGamma" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a joint random variable with generalized multivariate log gamma
distribution.</p>
<p>The joint pdf can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>syms: list/tuple/set of symbols for identifying each component</strong></p>
<p><strong>delta: A constant in range [0, 1]</strong></p>
<p><strong>v: Positive real number</strong></p>
<p><strong>lamda: List of positive real numbers</strong></p>
<p><strong>mu: List of positive real numbers</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats.joint_rv_types</span> <span class="kn">import</span> <span class="n">GeneralizedMultivariateLogGamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="p">,</span> <span class="n">mu</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;y_1:4&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Gd</span> <span class="o">=</span> <span class="n">GeneralizedMultivariateLogGamma</span><span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mu</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">Gd</span><span class="p">)(</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="go">Sum(exp((n + 1)*(y_1 + y_2 + y_3) - exp(y_1) - exp(y_2) -</span>
<span class="go">exp(y_3))/(2**n*gamma(n + 1)**3), (n, 0, oo))/2</span>
</pre></div>
</div>
<p class="rubric">Note</p>
<p>If the GeneralizedMultivariateLogGamma is too long to type use,
<span class="math notranslate nohighlight">\(from sympy.stats.joint_rv_types import GeneralizedMultivariateLogGamma as GMVLG\)</span>
If you want to pass the matrix omega instead of the constant delta, then use,
GeneralizedMultivariateLogGammaOmega.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r853"><span class="brackets"><a class="fn-backref" href="#id106">R853</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Generalized_multivariate_log-gamma_distribution">https://en.wikipedia.org/wiki/Generalized_multivariate_log-gamma_distribution</a></p>
</dd>
<dt class="label" id="r854"><span class="brackets"><a class="fn-backref" href="#id107">R854</a></span></dt>
<dd><p><a class="reference external" href="https://www.researchgate.net/publication/234137346_On_a_multivariate_log-gamma_distribution_and_the_use_of_the_distribution_in_the_Bayesian_analysis">https://www.researchgate.net/publication/234137346_On_a_multivariate_log-gamma_distribution_and_the_use_of_the_distribution_in_the_Bayesian_analysis</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.GeneralizedMultivariateLogGammaOmega">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">GeneralizedMultivariateLogGammaOmega</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">syms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">omega</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">v</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L706-L768"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.GeneralizedMultivariateLogGammaOmega" title="Permalink to this definition">¶</a></dt>
<dd><p>Extends GeneralizedMultivariateLogGamma.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>syms: list/tuple/set of symbols</strong></p>
<blockquote>
<div><p>For identifying each component</p>
</div></blockquote>
<p><strong>omega: A square matrix</strong></p>
<blockquote>
<div><p>Every element of square matrix must be absolute value of
square root of correlation coefficient</p>
</div></blockquote>
<p><strong>v: Positive real number</strong></p>
<p><strong>lamda: List of positive real numbers</strong></p>
<p><strong>mu: List of positive real numbers</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats.joint_rv_types</span> <span class="kn">import</span> <span class="n">GeneralizedMultivariateLogGammaOmega</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">omega</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">],</span> <span class="p">[</span><span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">],</span> <span class="p">[</span><span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="p">,</span> <span class="n">mu</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">GeneralizedMultivariateLogGammaOmega</span><span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="n">omega</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mu</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;y_1:4&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">G</span><span class="p">)(</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="go">sqrt(2)*Sum((1 - sqrt(2)/2)**n*exp((n + 1)*(y_1 + y_2 + y_3) - exp(y_1) -</span>
<span class="go">exp(y_2) - exp(y_3))/gamma(n + 1)**3, (n, 0, oo))/2</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>If the GeneralizedMultivariateLogGammaOmega is too long to type use,
<span class="math notranslate nohighlight">\(from sympy.stats.joint_rv_types import GeneralizedMultivariateLogGammaOmega as GMVLGO\)</span></p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r855"><span class="brackets"><a class="fn-backref" href="#id108">R855</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Generalized_multivariate_log-gamma_distribution">https://en.wikipedia.org/wiki/Generalized_multivariate_log-gamma_distribution</a></p>
</dd>
<dt class="label" id="r856"><span class="brackets"><a class="fn-backref" href="#id109">R856</a></span></dt>
<dd><p><a class="reference external" href="https://www.researchgate.net/publication/234137346_On_a_multivariate_log-gamma_distribution_and_the_use_of_the_distribution_in_the_Bayesian_analysis">https://www.researchgate.net/publication/234137346_On_a_multivariate_log-gamma_distribution_and_the_use_of_the_distribution_in_the_Bayesian_analysis</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Multinomial">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Multinomial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">syms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">p</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L800-L842"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Multinomial" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a discrete random variable with Multinomial Distribution.</p>
<p>The density of the said distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n: Positive integer</strong></p>
<blockquote>
<div><p>Represents number of trials</p>
</div></blockquote>
<p><strong>p: List of event probabilites</strong></p>
<blockquote>
<div><p>Must be in the range of [0, 1]</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span>  <span class="n">Multinomial</span><span class="p">,</span> <span class="n">marginal_distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">x3</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x1, x2, x3&#39;</span><span class="p">,</span> <span class="n">nonnegative</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">p3</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;p1, p2, p3&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Multinomial</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">p3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">M</span><span class="p">)(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">x3</span><span class="p">)</span>
<span class="go">Piecewise((6*p1**x1*p2**x2*p3**x3/(factorial(x1)*factorial(x2)*factorial(x3)),</span>
<span class="go">Eq(x1 + x2 + x3, 3)), (0, True))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">marginal_distribution</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">M</span><span class="p">[</span><span class="mi">0</span><span class="p">])(</span><span class="n">x1</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">3*p1*p2**2 + 6*p1*p2*p3 + 3*p1*p3**2</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r857"><span class="brackets"><a class="fn-backref" href="#id110">R857</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Multinomial_distribution">https://en.wikipedia.org/wiki/Multinomial_distribution</a></p>
</dd>
<dt class="label" id="r858"><span class="brackets"><a class="fn-backref" href="#id111">R858</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/MultinomialDistribution.html">http://mathworld.wolfram.com/MultinomialDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.MultivariateBeta">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">MultivariateBeta</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">syms</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">alpha</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L481-L524"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.MultivariateBeta" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a continuous random variable with Dirichlet/Multivariate Beta
Distribution.</p>
<p>The density of the dirichlet distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha: Positive real numbers</strong></p>
<blockquote>
<div><p>Signifies concentration numbers.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">MultivariateBeta</span><span class="p">,</span> <span class="n">marginal_distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a1</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;a1&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a2</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;a2&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MultivariateBeta</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">MultivariateBeta</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">B</span><span class="p">)(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">x**(a1 - 1)*y**(a2 - 1)*gamma(a1 + a2)/(gamma(a1)*gamma(a2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">marginal_distribution</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">C</span><span class="p">[</span><span class="mi">0</span><span class="p">])(</span><span class="n">x</span><span class="p">)</span>
<span class="go">x**(a1 - 1)*gamma(a1 + a2)/(a2*gamma(a1)*gamma(a2))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r859"><span class="brackets"><a class="fn-backref" href="#id112">R859</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Dirichlet_distribution">https://en.wikipedia.org/wiki/Dirichlet_distribution</a></p>
</dd>
<dt class="label" id="r860"><span class="brackets"><a class="fn-backref" href="#id113">R860</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/DirichletDistribution.html">http://mathworld.wolfram.com/DirichletDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.MultivariateEwens">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">MultivariateEwens</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">syms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">theta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L574-L614"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.MultivariateEwens" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a discrete random variable with Multivariate Ewens
Distribution.</p>
<p>The density of the said distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n: Positive integer</strong></p>
<blockquote>
<div><p>Size of the sample or the integer whose partitions are considered</p>
</div></blockquote>
<p><strong>theta: Positive real number</strong></p>
<blockquote>
<div><p>Denotes Mutation rate</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">marginal_distribution</span><span class="p">,</span> <span class="n">MultivariateEwens</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a1</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;a1&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a2</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;a2&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ed</span> <span class="o">=</span> <span class="n">MultivariateEwens</span><span class="p">(</span><span class="s1">&#39;E&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">ed</span><span class="p">)(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">)</span>
<span class="go">Piecewise((1/(2**a2*factorial(a1)*factorial(a2)), Eq(a1 + 2*a2, 2)), (0, True))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">marginal_distribution</span><span class="p">(</span><span class="n">ed</span><span class="p">,</span> <span class="n">ed</span><span class="p">[</span><span class="mi">0</span><span class="p">])(</span><span class="n">a1</span><span class="p">)</span>
<span class="go">Piecewise((1/factorial(a1), Eq(a1, 2)), (0, True))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r861"><span class="brackets"><a class="fn-backref" href="#id114">R861</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Ewens%27s_sampling_formula">https://en.wikipedia.org/wiki/Ewens%27s_sampling_formula</a></p>
</dd>
<dt class="label" id="r862"><span class="brackets"><a class="fn-backref" href="#id115">R862</a></span></dt>
<dd><p><a class="reference external" href="http://www.stat.rutgers.edu/home/hcrane/Papers/STS529.pdf">http://www.stat.rutgers.edu/home/hcrane/Papers/STS529.pdf</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.MultivariateT">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">MultivariateT</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">syms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">v</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L336-L367"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.MultivariateT" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a joint random variable with multivariate T-distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>syms: A symbol/str</strong></p>
<blockquote>
<div><p>For identifying the random variable.</p>
</div></blockquote>
<p><strong>mu: A list/matrix</strong></p>
<blockquote>
<div><p>Representing the location vector</p>
</div></blockquote>
<p><strong>sigma: The shape matrix for the distribution</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">MultivariateT</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MultivariateT</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]],</span> <span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">2/(9*pi)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.NegativeMultinomial">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">NegativeMultinomial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">syms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k0</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">p</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L873-L917"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.NegativeMultinomial" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a discrete random variable with Negative Multinomial Distribution.</p>
<p>The density of the said distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>k0: positive integer</strong></p>
<blockquote>
<div><p>Represents number of failures before the experiment is stopped</p>
</div></blockquote>
<p><strong>p: List of event probabilites</strong></p>
<blockquote>
<div><p>Must be in the range of [0, 1]</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">NegativeMultinomial</span><span class="p">,</span> <span class="n">marginal_distribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">x3</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x1, x2, x3&#39;</span><span class="p">,</span> <span class="n">nonnegative</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">p3</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;p1, p2, p3&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">NegativeMultinomial</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">p3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N_c</span> <span class="o">=</span> <span class="n">NegativeMultinomial</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">N</span><span class="p">)(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">x3</span><span class="p">)</span>
<span class="go">p1**x1*p2**x2*p3**x3*(-p1 - p2 - p3 + 1)**3*gamma(x1 + x2 +</span>
<span class="go">x3 + 3)/(2*factorial(x1)*factorial(x2)*factorial(x3))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">marginal_distribution</span><span class="p">(</span><span class="n">N_c</span><span class="p">,</span> <span class="n">N_c</span><span class="p">[</span><span class="mi">0</span><span class="p">])(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">()</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.25</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r863"><span class="brackets"><a class="fn-backref" href="#id116">R863</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Negative_multinomial_distribution">https://en.wikipedia.org/wiki/Negative_multinomial_distribution</a></p>
</dd>
<dt class="label" id="r864"><span class="brackets"><a class="fn-backref" href="#id117">R864</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/NegativeBinomialDistribution.html">http://mathworld.wolfram.com/NegativeBinomialDistribution.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.NormalGamma">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">NormalGamma</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sym</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/joint_rv_types.py#L412-L454"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.NormalGamma" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a bivariate joint random variable with multivariate Normal gamma
distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sym: A symbol/str</strong></p>
<blockquote>
<div><p>For identifying the random variable.</p>
</div></blockquote>
<p><strong>mu: A real number</strong></p>
<blockquote>
<div><p>The mean of the normal distribution</p>
</div></blockquote>
<p><strong>lamda: A positive integer</strong></p>
<blockquote>
<div><p>Parameter of joint distribution</p>
</div></blockquote>
<p><strong>alpha: A positive integer</strong></p>
<blockquote>
<div><p>Parameter of joint distribution</p>
</div></blockquote>
<p><strong>beta: A positive integer</strong></p>
<blockquote>
<div><p>Parameter of joint distribution</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">NormalGamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">NormalGamma</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;y z&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span>
<span class="go">9*sqrt(2)*z**(3/2)*exp(-3*z)*exp(-y**2*z/2)/(2*sqrt(pi))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r865"><span class="brackets"><a class="fn-backref" href="#id118">R865</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Normal-gamma_distribution">https://en.wikipedia.org/wiki/Normal-gamma_distribution</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="stochastic-processes">
<h3>Stochastic Processes<a class="headerlink" href="#stochastic-processes" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">DiscreteMarkovChain</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sym</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><a class="reference internal" href="core.html#sympy.core.basic.Basic" title="sympy.core.basic.Basic"><span class="pre">sympy.core.basic.Basic</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">state_space</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">Union</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="core.html#sympy.core.symbol.Symbol" title="sympy.core.symbol.Symbol"><span class="pre">sympy.core.symbol.Symbol</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">trans_probs</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">Sequence</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L791-L1467"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a finite discrete time-homogeneous Markov chain.</p>
<p>This type of Markov Chain can be uniquely characterised by
its (ordered) state space and its one-step transition probability
matrix.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sym:</strong></p>
<blockquote>
<div><p>The name given to the Markov Chain</p>
</div></blockquote>
<p><strong>state_space:</strong></p>
<blockquote>
<div><p>Optional, by default, Range(n)</p>
</div></blockquote>
<p><strong>trans_probs:</strong></p>
<blockquote>
<div><p>Optional, by default, MatrixSymbol(‘_T’, n, n)</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">DiscreteMarkovChain</span><span class="p">,</span> <span class="n">TransitionMatrixOf</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],[</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],[</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">YS</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span><span class="o">.</span><span class="n">state_space</span>
<span class="go">{0, 1, 2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span><span class="o">.</span><span class="n">transition_probabilities</span>
<span class="go">Matrix([</span>
<span class="go">[0.5, 0.2, 0.3],</span>
<span class="go">[0.2, 0.5, 0.3],</span>
<span class="go">[0.2, 0.3, 0.5]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">TS</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">YS</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="mi">2</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">YS</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">1</span><span class="p">)</span> <span class="o">&amp;</span> <span class="n">TransitionMatrixOf</span><span class="p">(</span><span class="n">YS</span><span class="p">,</span> <span class="n">TS</span><span class="p">))</span>
<span class="go">T[0, 2]*T[1, 0] + T[1, 1]*T[1, 2] + T[1, 2]*T[2, 2]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="mi">2</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.36</span>
</pre></div>
</div>
<p>Probabilities will be calculated based on indexes rather
than state names. For example, with the Sunny-Cloudy-Rainy
model with string state names:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.symbol</span> <span class="kn">import</span> <span class="n">Str</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">Str</span><span class="p">(</span><span class="s1">&#39;Sunny&#39;</span><span class="p">),</span> <span class="n">Str</span><span class="p">(</span><span class="s1">&#39;Cloudy&#39;</span><span class="p">),</span> <span class="n">Str</span><span class="p">(</span><span class="s1">&#39;Rainy&#39;</span><span class="p">)],</span> <span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="mi">2</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.36</span>
</pre></div>
</div>
<p>This gives the same answer as the <code class="docutils literal notranslate"><span class="pre">[0,</span> <span class="pre">1,</span> <span class="pre">2]</span></code> state space.
Currently, there is no support for state names within probability
and expectation statements. Here is a work-around using <code class="docutils literal notranslate"><span class="pre">Str</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">Str</span><span class="p">(</span><span class="s1">&#39;Rainy&#39;</span><span class="p">),</span> <span class="n">Y</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">Str</span><span class="p">(</span><span class="s1">&#39;Cloudy&#39;</span><span class="p">)))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.36</span>
</pre></div>
</div>
<p>Symbol state names can also be used:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sunny</span><span class="p">,</span> <span class="n">cloudy</span><span class="p">,</span> <span class="n">rainy</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;Sunny, Cloudy, Rainy&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">sunny</span><span class="p">,</span> <span class="n">cloudy</span><span class="p">,</span> <span class="n">rainy</span><span class="p">],</span> <span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">rainy</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">cloudy</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.36</span>
</pre></div>
</div>
<p>Expectations will be calculated as follows:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">cloudy</span><span class="p">))</span>
<span class="go">0.38*Cloudy + 0.36*Rainy + 0.26*Sunny</span>
</pre></div>
</div>
<p>Probability of expressions with multiple RandomIndexedSymbols
can also be calculated provided there is only 1 RandomIndexedSymbol
in the given condition. It is always better to use Rational instead
of floating point numbers for the probabilities in the
transition matrix to avoid errors.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Rational</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">)],</span> <span class="p">[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">)],</span> <span class="p">[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">10</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">Y</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">0.409</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Gt</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">Y</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.36</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Le</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">15</span><span class="p">],</span> <span class="n">Y</span><span class="p">[</span><span class="mi">10</span><span class="p">]),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">8</span><span class="p">],</span> <span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span>
<span class="go">0.6963328</span>
</pre></div>
</div>
<p>Symbolic probability queries are also supported</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">Gt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">P</span><span class="p">,</span> <span class="n">DiscreteMarkovChain</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b c d&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">)],</span> <span class="p">[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">10</span><span class="p">)],</span> <span class="p">[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query</span> <span class="o">=</span> <span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="n">a</span><span class="p">],</span> <span class="n">b</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">a</span><span class="p">:</span><span class="mi">10</span> <span class="p">,</span><span class="n">b</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span> <span class="n">d</span><span class="p">:</span><span class="mi">1</span><span class="p">})</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">0.3096</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span> <span class="mi">2</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">5</span><span class="p">],</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">evalf</span><span class="p">()</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">0.3096</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query_gt</span> <span class="o">=</span> <span class="n">P</span><span class="p">(</span><span class="n">Gt</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="n">a</span><span class="p">],</span> <span class="n">b</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query_gt</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">a</span><span class="p">:</span><span class="mi">21</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span> <span class="n">d</span><span class="p">:</span><span class="mi">0</span><span class="p">})</span><span class="o">.</span><span class="n">evalf</span><span class="p">()</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">0.64705</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Gt</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">21</span><span class="p">],</span> <span class="mi">0</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="mi">5</span><span class="p">],</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">0.64705</span>
</pre></div>
</div>
<p>There is limited support for arbitrarily sized states:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">nonnegative</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="n">trans_probs</span><span class="o">=</span><span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span><span class="o">.</span><span class="n">state_space</span>
<span class="go">Range(0, n, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query</span> <span class="o">=</span> <span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="n">a</span><span class="p">],</span> <span class="n">b</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Y</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">a</span><span class="p">:</span><span class="mi">10</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span> <span class="n">d</span><span class="p">:</span><span class="mi">1</span><span class="p">})</span>
<span class="go">(T**5)[1, 2]</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r866"><span class="brackets"><a class="fn-backref" href="#id119">R866</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Markov_chain#Discrete-time_Markov_chain">https://en.wikipedia.org/wiki/Markov_chain#Discrete-time_Markov_chain</a></p>
</dd>
<dt class="label" id="r867"><span class="brackets"><a class="fn-backref" href="#id120">R867</a></span></dt>
<dd><p><a class="reference external" href="https://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/Chapter11.pdf">https://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/Chapter11.pdf</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.absorbing_probabilities">
<span class="sig-name descname"><span class="pre">absorbing_probabilities</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1098-L1109"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.absorbing_probabilities" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the absorbing probabilities, i.e.,
the ij-th entry of the matrix denotes the
probability of Markov chain being absorbed
in state j starting from state i.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.canonical_form">
<span class="sig-name descname"><span class="pre">canonical_form</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">Tuple</span><span class="p"><span class="pre">[</span></span><span class="pre">List</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="core.html#sympy.core.basic.Basic" title="sympy.core.basic.Basic"><span class="pre">sympy.core.basic.Basic</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="matrices/immutablematrices.html#sympy.matrices.immutable.ImmutableDenseMatrix" title="sympy.matrices.immutable.ImmutableDenseMatrix"><span class="pre">sympy.matrices.immutable.ImmutableDenseMatrix</span></a><span class="p"><span class="pre">]</span></span></span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1347-L1442"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.canonical_form" title="Permalink to this definition">¶</a></dt>
<dd><p>Reorders the one-step transition matrix
so that recurrent states appear first and transient
states appear last. Other representations include inserting
transient states first and recurrent states last.</p>
<dl class="field-list">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>states, P_new</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">states</span></code> is the list that describes the order of the
new states in the matrix
so that the ith element in <code class="docutils literal notranslate"><span class="pre">states</span></code> is the state of the
ith row of A.
<code class="docutils literal notranslate"><span class="pre">P_new</span></code> is the new transition matrix in canonical form.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">DiscreteMarkovChain</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">S</span>
</pre></div>
</div>
<p>You can convert your chain into canonical form:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="mi">1</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">6</span><span class="p">)),</span> <span class="n">trans_probs</span><span class="o">=</span><span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">states</span><span class="p">,</span> <span class="n">new_matrix</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">canonical_form</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">states</span>
<span class="go">[3, 1, 2, 4, 5]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">new_matrix</span>
<span class="go">Matrix([</span>
<span class="go">[  1,   0,   0,   0,   0],</span>
<span class="go">[  0, 1/2, 1/2,   0,   0],</span>
<span class="go">[2/5, 2/5, 1/5,   0,   0],</span>
<span class="go">[1/2,   0,   0, 1/2,   0],</span>
<span class="go">[  0, 1/2,   0,   0, 1/2]])</span>
</pre></div>
</div>
<p>The new states are [3, 1, 2, 4, 5] and you can
create a new chain with this and its canonical
form will remain the same (since it is already
in canonical form).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">states</span><span class="p">,</span> <span class="n">new_matrix</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">states</span><span class="p">,</span> <span class="n">new_matrix</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">canonical_form</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">states</span>
<span class="go">[3, 1, 2, 4, 5]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">new_matrix</span>
<span class="go">Matrix([</span>
<span class="go">[  1,   0,   0,   0,   0],</span>
<span class="go">[  0, 1/2, 1/2,   0,   0],</span>
<span class="go">[2/5, 2/5, 1/5,   0,   0],</span>
<span class="go">[1/2,   0,   0, 1/2,   0],</span>
<span class="go">[  0, 1/2,   0,   0, 1/2]])</span>
</pre></div>
</div>
<p>This is not limited to absorbing chains:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span>  <span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>  <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>  <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>  <span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>  <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>  <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span>  <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span>  <span class="mi">4</span><span class="p">]])</span><span class="o">/</span><span class="mi">10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">trans_probs</span><span class="o">=</span><span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">states</span><span class="p">,</span> <span class="n">new_matrix</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">canonical_form</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">states</span>
<span class="go">[1, 3, 0, 2, 4]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">new_matrix</span>
<span class="go">Matrix([</span>
<span class="go">[   0,    1,   0,   0,   0],</span>
<span class="go">[   1,    0,   0,   0,   0],</span>
<span class="go">[ 1/2,    0,   0, 1/2,   0],</span>
<span class="go">[   0,    0, 1/2, 1/2,   0],</span>
<span class="go">[3/10, 3/10,   0,   0, 2/5]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.DiscreteMarkovChain.communication_classes" title="sympy.stats.DiscreteMarkovChain.communication_classes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.stats.DiscreteMarkovChain.communication_classes</span></code></a>, <a class="reference internal" href="#sympy.stats.DiscreteMarkovChain.decompose" title="sympy.stats.DiscreteMarkovChain.decompose"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.stats.DiscreteMarkovChain.decompose</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r868"><span class="brackets"><a class="fn-backref" href="#id121">R868</a></span></dt>
<dd><p><a class="reference external" href="https://onlinelibrary.wiley.com/doi/pdf/10.1002/9780470316887.app1">https://onlinelibrary.wiley.com/doi/pdf/10.1002/9780470316887.app1</a></p>
</dd>
<dt class="label" id="r869"><span class="brackets"><a class="fn-backref" href="#id122">R869</a></span></dt>
<dd><p><a class="reference external" href="http://www.columbia.edu/~ww2040/6711F12/lect1023big.pdf">http://www.columbia.edu/~ww2040/6711F12/lect1023big.pdf</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.communication_classes">
<span class="sig-name descname"><span class="pre">communication_classes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">List</span><span class="p"><span class="pre">[</span></span><span class="pre">Tuple</span><span class="p"><span class="pre">[</span></span><span class="pre">List</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="core.html#sympy.core.basic.Basic" title="sympy.core.basic.Basic"><span class="pre">sympy.core.basic.Basic</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="logic.html#sympy.logic.boolalg.Boolean" title="sympy.logic.boolalg.Boolean"><span class="pre">sympy.logic.boolalg.Boolean</span></a><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="core.html#sympy.core.numbers.Integer" title="sympy.core.numbers.Integer"><span class="pre">sympy.core.numbers.Integer</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L934-L1068"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.communication_classes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of communication classes that partition
the states of the markov chain.</p>
<p>A communication class is defined to be a set of states
such that every state in that set is reachable from
every other state in that set. Due to its properties
this forms a class in the mathematical sense.
Communication classes are also known as recurrence
classes.</p>
<dl class="field-list">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>classes</p>
<blockquote>
<div><p>The <code class="docutils literal notranslate"><span class="pre">classes</span></code> are a list of tuples. Each
tuple represents a single communication class
with its properties. The first element in the
tuple is the list of states in the class, the
second element is whether the class is recurrent
and the third element is the period of the
communication class.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">DiscreteMarkovChain</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">classes</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">communication_classes</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">states</span><span class="p">,</span> <span class="n">is_recurrent</span><span class="p">,</span> <span class="n">period</span> <span class="ow">in</span> <span class="n">classes</span><span class="p">:</span>
<span class="gp">... </span>    <span class="n">states</span><span class="p">,</span> <span class="n">is_recurrent</span><span class="p">,</span> <span class="n">period</span>
<span class="go">([1, 2], True, 2)</span>
<span class="go">([3], False, 1)</span>
</pre></div>
</div>
<p>From this we can see that states <code class="docutils literal notranslate"><span class="pre">1</span></code> and <code class="docutils literal notranslate"><span class="pre">2</span></code>
communicate, are recurrent and have a period
of 2. We can also see state <code class="docutils literal notranslate"><span class="pre">3</span></code> is transient
with a period of 1.</p>
<p class="rubric">Notes</p>
<p>The algorithm used is of order <code class="docutils literal notranslate"><span class="pre">O(n**2)</span></code> where
<code class="docutils literal notranslate"><span class="pre">n</span></code> is the number of states in the markov chain.
It uses Tarjan’s algorithm to find the classes
themselves and then it uses a breadth-first search
algorithm to find each class’s periodicity.
Most of the algorithm’s components approach <code class="docutils literal notranslate"><span class="pre">O(n)</span></code>
as the matrix becomes more and more sparse.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r870"><span class="brackets"><a class="fn-backref" href="#id123">R870</a></span></dt>
<dd><p><a class="reference external" href="http://www.columbia.edu/~ww2040/4701Sum07/4701-06-Notes-MCII.pdf">http://www.columbia.edu/~ww2040/4701Sum07/4701-06-Notes-MCII.pdf</a></p>
</dd>
<dt class="label" id="r871"><span class="brackets"><a class="fn-backref" href="#id124">R871</a></span></dt>
<dd><p><a class="reference external" href="http://cecas.clemson.edu/~shierd/Shier/markov.pdf">http://cecas.clemson.edu/~shierd/Shier/markov.pdf</a></p>
</dd>
<dt class="label" id="r872"><span class="brackets"><a class="fn-backref" href="#id125">R872</a></span></dt>
<dd><p><a class="reference external" href="https://ujcontent.uj.ac.za/vital/access/services/Download/uj:7506/CONTENT1">https://ujcontent.uj.ac.za/vital/access/services/Download/uj:7506/CONTENT1</a></p>
</dd>
<dt class="label" id="r873"><span class="brackets"><a class="fn-backref" href="#id126">R873</a></span></dt>
<dd><p><a class="reference external" href="https://www.mathworks.com/help/econ/dtmc.classify.html">https://www.mathworks.com/help/econ/dtmc.classify.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.decompose">
<span class="sig-name descname"><span class="pre">decompose</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">Tuple</span><span class="p"><span class="pre">[</span></span><span class="pre">List</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="core.html#sympy.core.basic.Basic" title="sympy.core.basic.Basic"><span class="pre">sympy.core.basic.Basic</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="matrices/immutablematrices.html#sympy.matrices.immutable.ImmutableDenseMatrix" title="sympy.matrices.immutable.ImmutableDenseMatrix"><span class="pre">sympy.matrices.immutable.ImmutableDenseMatrix</span></a><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="matrices/immutablematrices.html#sympy.matrices.immutable.ImmutableDenseMatrix" title="sympy.matrices.immutable.ImmutableDenseMatrix"><span class="pre">sympy.matrices.immutable.ImmutableDenseMatrix</span></a><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="matrices/immutablematrices.html#sympy.matrices.immutable.ImmutableDenseMatrix" title="sympy.matrices.immutable.ImmutableDenseMatrix"><span class="pre">sympy.matrices.immutable.ImmutableDenseMatrix</span></a><span class="p"><span class="pre">]</span></span></span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1245-L1345"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.decompose" title="Permalink to this definition">¶</a></dt>
<dd><p>Decomposes the transition matrix into submatrices with
special properties.</p>
<p>The transition matrix can be decomposed into 4 submatrices:
- A - the submatrix from recurrent states to recurrent states.
- B - the submatrix from transient to recurrent states.
- C - the submatrix from transient to transient states.
- O - the submatrix of zeros for recurrent to transient states.</p>
<dl class="field-list">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>states, A, B, C</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">states</span></code> - a list of state names with the first being
the recurrent states and the last being
the transient states in the order
of the row names of A and then the row names of C.
<code class="docutils literal notranslate"><span class="pre">A</span></code> - the submatrix from recurrent states to recurrent states.
<code class="docutils literal notranslate"><span class="pre">B</span></code> - the submatrix from transient to recurrent states.
<code class="docutils literal notranslate"><span class="pre">C</span></code> - the submatrix from transient to transient states.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">DiscreteMarkovChain</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">S</span>
</pre></div>
</div>
<p>One can decompose this chain for example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="mi">1</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span>      <span class="mi">0</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">trans_probs</span><span class="o">=</span><span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">states</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">decompose</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">states</span>
<span class="go">[2, 0, 1, 3, 4]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span>   <span class="c1"># recurrent to recurrent</span>
<span class="go">Matrix([[1]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">B</span>  <span class="c1"># transient to recurrent</span>
<span class="go">Matrix([</span>
<span class="go">[  0],</span>
<span class="go">[2/5],</span>
<span class="go">[1/2],</span>
<span class="go">[  0]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span>  <span class="c1"># transient to transient</span>
<span class="go">Matrix([</span>
<span class="go">[1/2, 1/2,   0,   0],</span>
<span class="go">[2/5, 1/5,   0,   0],</span>
<span class="go">[  0,   0, 1/2,   0],</span>
<span class="go">[1/2,   0,   0, 1/2]])</span>
</pre></div>
</div>
<p>This means that state 2 is the only absorbing state
(since A is a 1x1 matrix). B is a 4x1 matrix since
the 4 remaining transient states all merge into reccurent
state 2. And C is the 4x4 matrix that shows how the
transient states 0, 1, 3, 4 all interact.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.DiscreteMarkovChain.communication_classes" title="sympy.stats.DiscreteMarkovChain.communication_classes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.stats.DiscreteMarkovChain.communication_classes</span></code></a>, <a class="reference internal" href="#sympy.stats.DiscreteMarkovChain.canonical_form" title="sympy.stats.DiscreteMarkovChain.canonical_form"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.stats.DiscreteMarkovChain.canonical_form</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r874"><span class="brackets"><a class="fn-backref" href="#id127">R874</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Absorbing_Markov_chain">https://en.wikipedia.org/wiki/Absorbing_Markov_chain</a></p>
</dd>
<dt class="label" id="r875"><span class="brackets"><a class="fn-backref" href="#id128">R875</a></span></dt>
<dd><p><a class="reference external" href="http://people.brandeis.edu/~igusa/Math56aS08/Math56a_S08_notes015.pdf">http://people.brandeis.edu/~igusa/Math56aS08/Math56a_S08_notes015.pdf</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.fixed_row_vector">
<span class="sig-name descname"><span class="pre">fixed_row_vector</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1231-L1235"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.fixed_row_vector" title="Permalink to this definition">¶</a></dt>
<dd><p>A wrapper for <code class="docutils literal notranslate"><span class="pre">stationary_distribution()</span></code>.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.fundamental_matrix">
<span class="sig-name descname"><span class="pre">fundamental_matrix</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1070-L1096"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.fundamental_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Each entry fundamental matrix can be interpreted as
the expected number of times the chains is in state j
if it started in state i.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r876"><span class="brackets"><a class="fn-backref" href="#id129">R876</a></span></dt>
<dd><p><a class="reference external" href="https://lips.cs.princeton.edu/the-fundamental-matrix-of-a-finite-markov-chain/">https://lips.cs.princeton.edu/the-fundamental-matrix-of-a-finite-markov-chain/</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.limiting_distribution">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">limiting_distribution</span></span><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.limiting_distribution" title="Permalink to this definition">¶</a></dt>
<dd><p>The fixed row vector is the limiting
distribution of a discrete Markov chain.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.sample">
<span class="sig-name descname"><span class="pre">sample</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1444-L1467"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.sample" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>sample: iterator object</p>
<blockquote>
<div><p>iterator object containing the sample</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.stationary_distribution">
<span class="sig-name descname"><span class="pre">stationary_distribution</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">condition_set</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">Union</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="matrices/immutablematrices.html#sympy.matrices.immutable.ImmutableDenseMatrix" title="sympy.matrices.immutable.ImmutableDenseMatrix"><span class="pre">sympy.matrices.immutable.ImmutableDenseMatrix</span></a><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="sets.html#sympy.sets.conditionset.ConditionSet" title="sympy.sets.conditionset.ConditionSet"><span class="pre">sympy.sets.conditionset.ConditionSet</span></a><span class="p"><span class="pre">,</span> </span><a class="reference internal" href="core.html#sympy.core.function.Lambda" title="sympy.core.function.Lambda"><span class="pre">sympy.core.function.Lambda</span></a><span class="p"><span class="pre">]</span></span></span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1145-L1229"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.stationary_distribution" title="Permalink to this definition">¶</a></dt>
<dd><p>The stationary distribution is any row vector, p, that solves p = pP,
is row stochastic and each element in p must be nonnegative.
That means in matrix form: <span class="math notranslate nohighlight">\((P-I)^T p^T = 0\)</span> and
<span class="math notranslate nohighlight">\((1, ..., 1) p = 1\)</span>
where <code class="docutils literal notranslate"><span class="pre">P</span></code> is the one-step transition matrix.</p>
<p>All time-homogeneous Markov Chains with a finite state space
have at least one stationary distribution. In addition, if
a finite time-homogeneous Markov Chain is irreducible, the
stationary distribution is unique.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>condition_set</strong> : bool</p>
<blockquote>
<div><p>If the chain has a symbolic size or transition matrix,
it will return a <code class="docutils literal notranslate"><span class="pre">Lambda</span></code> if <code class="docutils literal notranslate"><span class="pre">False</span></code> and return a
<code class="docutils literal notranslate"><span class="pre">ConditionSet</span></code> if <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">DiscreteMarkovChain</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">S</span>
</pre></div>
</div>
<p>An irreducible Markov Chain</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">trans_probs</span><span class="o">=</span><span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">stationary_distribution</span><span class="p">()</span>
<span class="go">Matrix([[8/13, 5/13, 0]])</span>
</pre></div>
</div>
<p>A reducible Markov Chain</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">trans_probs</span><span class="o">=</span><span class="n">T</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">stationary_distribution</span><span class="p">()</span>
<span class="go">Matrix([[8/13 - 8*tau0/13, 5/13 - 5*tau0/13, tau0]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">DiscreteMarkovChain</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span><span class="o">.</span><span class="n">stationary_distribution</span><span class="p">()</span>
<span class="go">Lambda((wm, _T), Eq(wm*_T, wm))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span><span class="o">.</span><span class="n">stationary_distribution</span><span class="p">(</span><span class="n">condition_set</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">ConditionSet(wm, Eq(wm*_T, wm))</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.DiscreteMarkovChain.limiting_distribution" title="sympy.stats.DiscreteMarkovChain.limiting_distribution"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.stats.DiscreteMarkovChain.limiting_distribution</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r877"><span class="brackets"><a class="fn-backref" href="#id130">R877</a></span></dt>
<dd><p><a class="reference external" href="https://www.probabilitycourse.com/chapter11/11_2_6_stationary_and_limiting_distributions.php">https://www.probabilitycourse.com/chapter11/11_2_6_stationary_and_limiting_distributions.php</a></p>
</dd>
<dt class="label" id="r878"><span class="brackets"><a class="fn-backref" href="#id131">R878</a></span></dt>
<dd><p><a class="reference external" href="https://galton.uchicago.edu/~yibi/teaching/stat317/2014/Lectures/Lecture4_6up.pdf">https://galton.uchicago.edu/~yibi/teaching/stat317/2014/Lectures/Lecture4_6up.pdf</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.stats.DiscreteMarkovChain.transition_probabilities">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">transition_probabilities</span></span><em class="property"><span class="pre">:</span> <span class="pre">Union[sympy.matrices.matrices.MatrixBase,</span> <span class="pre">sympy.matrices.expressions.matexpr.MatrixSymbol]</span></em><a class="headerlink" href="#sympy.stats.DiscreteMarkovChain.transition_probabilities" title="Permalink to this definition">¶</a></dt>
<dd><p>Transition probabilities of discrete Markov chain,
either an instance of Matrix or MatrixSymbol.</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.ContinuousMarkovChain">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">ContinuousMarkovChain</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sym</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">state_space</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gen_mat</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1469-L1586"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.ContinuousMarkovChain" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents continuous time Markov chain.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sym: Symbol/str</strong></p>
<p><strong>state_space: Set</strong></p>
<blockquote>
<div><p>Optional, by default, S.Reals</p>
</div></blockquote>
<p><strong>gen_mat: Matrix/ImmutableMatrix/MatrixSymbol</strong></p>
<blockquote>
<div><p>Optional, by default, None</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ContinuousMarkovChain</span><span class="p">,</span> <span class="n">P</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">Gt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)],</span> <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="o">-</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">ContinuousMarkovChain</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">state_space</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="n">gen_mat</span><span class="o">=</span><span class="n">G</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">limiting_distribution</span><span class="p">()</span>
<span class="go">Matrix([[1/2, 1/2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">state_space</span>
<span class="go">{0, 1}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">generator_matrix</span>
<span class="go">Matrix([</span>
<span class="go">[-1,  1],</span>
<span class="go">[ 1, -1]])</span>
</pre></div>
</div>
<p>Probability queries are supported</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">1.96</span><span class="p">),</span> <span class="mi">0</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">0.78</span><span class="p">),</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">0.45279</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Gt</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">1.7</span><span class="p">),</span> <span class="mi">0</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">0.82</span><span class="p">),</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">0.58602</span>
</pre></div>
</div>
<p>Probability of expressions with multiple RandomIndexedSymbols
can also be calculated provided there is only 1 RandomIndexedSymbol
in the given condition. It is always better to use Rational instead
of floating point numbers for the probabilities in the
generator matrix to avoid errors.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Rational</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">)],</span> <span class="p">[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="o">-</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">)],</span> <span class="p">[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="o">-</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">ContinuousMarkovChain</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">state_space</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">gen_mat</span><span class="o">=</span><span class="n">G</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">3.92</span><span class="p">),</span> <span class="n">C</span><span class="p">(</span><span class="mf">1.75</span><span class="p">)),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">0.46</span><span class="p">),</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">0.37933</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Gt</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">3.92</span><span class="p">),</span> <span class="n">C</span><span class="p">(</span><span class="mf">1.75</span><span class="p">)),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">0.46</span><span class="p">),</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">0.34211</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Le</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">1.57</span><span class="p">),</span> <span class="n">C</span><span class="p">(</span><span class="mf">3.14</span><span class="p">)),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">1.22</span><span class="p">),</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">0.7143</span>
</pre></div>
</div>
<p>Symbolic probability queries are also supported</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">Gt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">P</span><span class="p">,</span> <span class="n">ContinuousMarkovChain</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">,</span><span class="n">d</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b c d&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">)],</span> <span class="p">[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="o">-</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">)],</span> <span class="p">[</span><span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="o">-</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">ContinuousMarkovChain</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">state_space</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">gen_mat</span><span class="o">=</span><span class="n">G</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query</span> <span class="o">=</span> <span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">b</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">a</span><span class="p">:</span><span class="mf">3.65</span> <span class="p">,</span><span class="n">b</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span><span class="mf">1.78</span><span class="p">,</span> <span class="n">d</span><span class="p">:</span><span class="mi">1</span><span class="p">})</span><span class="o">.</span><span class="n">evalf</span><span class="p">()</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">0.4002723175</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">3.65</span><span class="p">),</span> <span class="mi">2</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">1.78</span><span class="p">),</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">0.4002723175</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query_gt</span> <span class="o">=</span> <span class="n">P</span><span class="p">(</span><span class="n">Gt</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">b</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">query_gt</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">a</span><span class="p">:</span><span class="mf">43.2</span> <span class="p">,</span><span class="n">b</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span><span class="mf">3.29</span><span class="p">,</span> <span class="n">d</span><span class="p">:</span><span class="mi">2</span><span class="p">})</span><span class="o">.</span><span class="n">evalf</span><span class="p">()</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">0.6832579186</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Gt</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">43.2</span><span class="p">),</span> <span class="mi">0</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">C</span><span class="p">(</span><span class="mf">3.29</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">0.6832579186</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r879"><span class="brackets"><a class="fn-backref" href="#id132">R879</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Markov_chain#Continuous-time_Markov_chain">https://en.wikipedia.org/wiki/Markov_chain#Continuous-time_Markov_chain</a></p>
</dd>
<dt class="label" id="r880"><span class="brackets"><a class="fn-backref" href="#id133">R880</a></span></dt>
<dd><p><a class="reference external" href="http://u.math.biu.ac.il/~amirgi/CTMCnotes.pdf">http://u.math.biu.ac.il/~amirgi/CTMCnotes.pdf</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.BernoulliProcess">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">BernoulliProcess</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sym</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">success</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">failure</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1589-L1738"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.BernoulliProcess" title="Permalink to this definition">¶</a></dt>
<dd><p>The Bernoulli process consists of repeated
independent Bernoulli process trials with the same parameter <span class="math notranslate nohighlight">\(p\)</span>.
It’s assumed that the probability <span class="math notranslate nohighlight">\(p\)</span> applies to every
trial and that the outcomes of each trial
are independent of all the rest. Therefore Bernoulli Processs
is Discrete State and Discrete Time Stochastic Process.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sym: Symbol/str</strong></p>
<p><strong>success: Integer/str</strong></p>
<blockquote>
<div><p>The event which is considered to be success, by default is 1.</p>
</div></blockquote>
<p><strong>failure: Integer/str</strong></p>
<blockquote>
<div><p>The event which is considered to be failure, by default is 0.</p>
</div></blockquote>
<p><strong>p: Real Number between 0 and 1</strong></p>
<blockquote>
<div><p>Represents the probability of getting success.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">BernoulliProcess</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">Gt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">BernoulliProcess</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="mf">0.7</span><span class="p">,</span> <span class="n">success</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">failure</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">state_space</span>
<span class="go">{0, 1}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">B</span><span class="o">.</span><span class="n">p</span><span class="p">)</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.70</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">success</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">failure</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">B</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">B</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="n">B</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.03</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.44</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Gt</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.78</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">B</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">0</span><span class="p">)</span> <span class="o">&amp;</span> <span class="n">Eq</span><span class="p">(</span><span class="n">B</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mi">1</span><span class="p">)</span> <span class="o">&amp;</span> <span class="n">Eq</span><span class="p">(</span><span class="n">B</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="mi">0</span><span class="p">)</span> <span class="o">&amp;</span> <span class="n">Eq</span><span class="p">(</span><span class="n">B</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.04</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">joint_distribution</span><span class="p">(</span><span class="n">B</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">B</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="go">JointDistributionHandmade(Lambda((B[1], B[2]), Piecewise((0.7, Eq(B[1], 1)),</span>
<span class="go">(0.3, Eq(B[1], 0)), (0, True))*Piecewise((0.7, Eq(B[2], 1)), (0.3, Eq(B[2], 0)),</span>
<span class="go">(0, True))))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">B</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">B</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">2.10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">B</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.30</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r881"><span class="brackets"><a class="fn-backref" href="#id134">R881</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Bernoulli_process">https://en.wikipedia.org/wiki/Bernoulli_process</a></p>
</dd>
<dt class="label" id="r882"><span class="brackets"><a class="fn-backref" href="#id135">R882</a></span></dt>
<dd><p><a class="reference external" href="https://mathcs.clarku.edu/~djoyce/ma217/bernoulli.pdf">https://mathcs.clarku.edu/~djoyce/ma217/bernoulli.pdf</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.BernoulliProcess.expectation">
<span class="sig-name descname"><span class="pre">expectation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1691-L1711"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.BernoulliProcess.expectation" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes expectation.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr: RandomIndexedSymbol, Relational, Logic</strong></p>
<blockquote>
<div><p>Condition for which expectation has to be computed. Must
contain a RandomIndexedSymbol of the process.</p>
</div></blockquote>
<p><strong>condition: Relational, Logic</strong></p>
<blockquote>
<div><p>The given conditions under which computations should be done.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Expectation of the RandomIndexedSymbol.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.stats.BernoulliProcess.probability">
<span class="sig-name descname"><span class="pre">probability</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">condition</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">given_condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L1713-L1733"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.BernoulliProcess.probability" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes probability.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>condition: Relational</strong></p>
<blockquote>
<div><p>Condition for which probability has to be computed. Must
contain a RandomIndexedSymbol of the process.</p>
</div></blockquote>
<p><strong>given_condition: Relational/And</strong></p>
<blockquote>
<div><p>The given conditions under which computations should be done.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Probability of the condition.</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.PoissonProcess">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">PoissonProcess</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sym</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L2121-L2220"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.PoissonProcess" title="Permalink to this definition">¶</a></dt>
<dd><p>The Poisson process is a counting process. It is usually used in scenarios
where we are counting the occurrences of certain events that appear
to happen at a certain rate, but completely at random.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sym: Symbol/str</strong></p>
<p><strong>lamda: Positive number</strong></p>
<blockquote>
<div><p>Rate of the process, <code class="docutils literal notranslate"><span class="pre">lamda</span> <span class="pre">&gt;</span> <span class="pre">0</span></code></p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">PoissonProcess</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">Ne</span><span class="p">,</span> <span class="n">Contains</span><span class="p">,</span> <span class="n">Interval</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">PoissonProcess</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="n">lamda</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">state_space</span>
<span class="go">Naturals0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">lamda</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t1</span><span class="p">,</span> <span class="n">t2</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;t1 t2&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">(9*t1**3/2 + 9*t1**2/2 + 3*t1 + 1)*exp(-3*t1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span> <span class="o">|</span> <span class="n">Ne</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">),</span> <span class="mi">4</span><span class="p">),</span> <span class="n">Contains</span><span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Ropen</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)))</span>
<span class="go">1 - 36*exp(-6)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span> <span class="o">&amp;</span> <span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t2</span><span class="p">),</span> <span class="mi">3</span><span class="p">),</span> <span class="n">Contains</span><span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Lopen</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="gp">... </span><span class="o">&amp;</span> <span class="n">Contains</span><span class="p">(</span><span class="n">t2</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Lopen</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)))</span>
<span class="go">648*exp(-12)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">))</span>
<span class="go">3*t1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">X</span><span class="p">(</span><span class="n">t2</span><span class="p">),</span>  <span class="n">Contains</span><span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Lopen</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">... </span><span class="o">&amp;</span> <span class="n">Contains</span><span class="p">(</span><span class="n">t2</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Lopen</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)))</span>
<span class="go">18</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">,</span> <span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">exp(-6)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="mi">3</span><span class="p">),</span> <span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="mi">3</span><span class="p">))</span>
<span class="go">exp(-6)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">3</span><span class="p">,</span> <span class="n">X</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">5*exp(-3)</span>
</pre></div>
</div>
<p>Merging two Poisson Processes</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">PoissonProcess</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="n">lamda</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">X</span> <span class="o">+</span> <span class="n">Y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span><span class="o">.</span><span class="n">lamda</span>
<span class="go">7</span>
</pre></div>
</div>
<p>Splitting a Poisson Process into two independent Poisson Processes</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">,</span> <span class="n">M</span> <span class="o">=</span> <span class="n">Z</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">l1</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">l2</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">lamda</span><span class="p">,</span> <span class="n">M</span><span class="o">.</span><span class="n">lamda</span>
<span class="go">(2, 5)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r883"><span class="brackets"><a class="fn-backref" href="#id136">R883</a></span></dt>
<dd><p><a class="reference external" href="https://www.probabilitycourse.com/chapter11/11_0_0_intro.php">https://www.probabilitycourse.com/chapter11/11_0_0_intro.php</a></p>
</dd>
<dt class="label" id="r884"><span class="brackets"><a class="fn-backref" href="#id137">R884</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Poisson_point_process">https://en.wikipedia.org/wiki/Poisson_point_process</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.WienerProcess">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">WienerProcess</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sym</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L2222-L2277"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.WienerProcess" title="Permalink to this definition">¶</a></dt>
<dd><p>The Wiener process is a real valued continuous-time stochastic process.
In physics it is used to study Brownian motion and therefore also known as
Brownian Motion.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sym: Symbol/str</strong></p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">WienerProcess</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Contains</span><span class="p">,</span> <span class="n">Interval</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">WienerProcess</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">state_space</span>
<span class="go">Reals</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t1</span><span class="p">,</span> <span class="n">t2</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;t1 t2&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">7</span><span class="p">)</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">erf(7*sqrt(2)/(2*sqrt(t1)))/2 + 1/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">((</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">4</span><span class="p">),</span> <span class="n">Contains</span><span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Ropen</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)))</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">-erf(1)/2 + erf(2)/2 + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">))</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t1</span><span class="p">)</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">X</span><span class="p">(</span><span class="n">t2</span><span class="p">),</span>  <span class="n">Contains</span><span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Lopen</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">... </span><span class="o">&amp;</span> <span class="n">Contains</span><span class="p">(</span><span class="n">t2</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Lopen</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)))</span>
<span class="go">0</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r885"><span class="brackets"><a class="fn-backref" href="#id138">R885</a></span></dt>
<dd><p><a class="reference external" href="https://www.probabilitycourse.com/chapter11/11_4_0_brownian_motion_wiener_process.php">https://www.probabilitycourse.com/chapter11/11_4_0_brownian_motion_wiener_process.php</a></p>
</dd>
<dt class="label" id="r886"><span class="brackets"><a class="fn-backref" href="#id139">R886</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Wiener_process">https://en.wikipedia.org/wiki/Wiener_process</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.GammaProcess">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">GammaProcess</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sym</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gamma</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/stochastic_process_types.py#L2280-L2352"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.GammaProcess" title="Permalink to this definition">¶</a></dt>
<dd><p>A Gamma process is a random process with independent gamma distributed
increments.  It is a pure-jump increasing Levy process.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sym: Symbol/str</strong></p>
<p><strong>lamda: Positive number</strong></p>
<blockquote>
<div><p>Jump size of the process, <code class="docutils literal notranslate"><span class="pre">lamda</span> <span class="pre">&gt;</span> <span class="pre">0</span></code></p>
</div></blockquote>
<p><strong>gamma: Positive number</strong></p>
<blockquote>
<div><p>Rate of jump arrivals, <code class="docutils literal notranslate"><span class="pre">gamma</span> <span class="pre">&gt;</span> <span class="pre">0</span></code></p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">GammaProcess</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Contains</span><span class="p">,</span> <span class="n">Interval</span><span class="p">,</span> <span class="n">Not</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">g</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;t d x l g&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">GammaProcess</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">g</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t</span><span class="p">))</span>
<span class="go">g*t/l</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t</span><span class="p">))</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">g*t/l**2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">GammaProcess</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">lowergamma(2*t, 1)/gamma(2*t)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Not</span><span class="p">((</span><span class="n">X</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">5</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">)),</span> <span class="n">Contains</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Ropen</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span> <span class="o">&amp;</span>
<span class="gp">... </span><span class="n">Contains</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Lopen</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">)))</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">-4*exp(-3) + 472*exp(-8)/3 + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">(</span><span class="mi">5</span><span class="p">)))</span>
<span class="go">10*x + 4</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r887"><span class="brackets"><a class="fn-backref" href="#id140">R887</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Gamma_process">https://en.wikipedia.org/wiki/Gamma_process</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="matrix-distributions">
<h3>Matrix Distributions<a class="headerlink" href="#matrix-distributions" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.MatrixGamma">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">MatrixGamma</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symbol</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">beta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scale_matrix</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/matrix_distributions.py#L267-L312"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.MatrixGamma" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a random variable with Matrix Gamma Distribution.</p>
<p>The density of the said distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>alpha: Positive Real number</strong></p>
<blockquote>
<div><p>Shape Parameter</p>
</div></blockquote>
<p><strong>beta: Positive Real number</strong></p>
<blockquote>
<div><p>Scale Parameter</p>
</div></blockquote>
<p><strong>scale_matrix: Positive definite real square matrix</strong></p>
<blockquote>
<div><p>Scale Matrix</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">MatrixGamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">MatrixGamma</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="p">[[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">M</span><span class="p">)(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">exp(Trace(Matrix([</span>
<span class="go">[-2/3,  1/3],</span>
<span class="go">[ 1/3, -2/3]])*X)/b)*Determinant(X)**(a - 3/2)/(3**a*sqrt(pi)*b**(2*a)*gamma(a)*gamma(a - 1/2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">M</span><span class="p">)([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">exp(-4/(3*b))/(3**a*sqrt(pi)*b**(2*a)*gamma(a)*gamma(a - 1/2))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r888"><span class="brackets"><a class="fn-backref" href="#id141">R888</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Matrix_gamma_distribution">https://en.wikipedia.org/wiki/Matrix_gamma_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.Wishart">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Wishart</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symbol</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scale_matrix</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/matrix_distributions.py#L353-L395"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Wishart" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a random variable with Wishart Distribution.</p>
<p>The density of the said distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n: Positive Real number</strong></p>
<blockquote>
<div><p>Represents degrees of freedom</p>
</div></blockquote>
<p><strong>scale_matrix: Positive definite real square matrix</strong></p>
<blockquote>
<div><p>Scale Matrix</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">Wishart</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">W</span> <span class="o">=</span> <span class="n">Wishart</span><span class="p">(</span><span class="s1">&#39;W&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="p">[[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">W</span><span class="p">)(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">exp(Trace(Matrix([</span>
<span class="go">[-1/3,  1/6],</span>
<span class="go">[ 1/6, -1/3]])*X))*Determinant(X)**(n/2 - 3/2)/(2**n*3**(n/2)*sqrt(pi)*gamma(n/2)*gamma(n/2 - 1/2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">W</span><span class="p">)([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">exp(-2/3)/(2**n*3**(n/2)*sqrt(pi)*gamma(n/2)*gamma(n/2 - 1/2))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r889"><span class="brackets"><a class="fn-backref" href="#id142">R889</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Wishart_distribution">https://en.wikipedia.org/wiki/Wishart_distribution</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.MatrixNormal">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">MatrixNormal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symbol</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">location_matrix</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scale_matrix_1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scale_matrix_2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/matrix_distributions.py#L445-L493"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.MatrixNormal" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a random variable with Matrix Normal Distribution.</p>
<p>The density of the said distribution can be found at [1].</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>location_matrix: Real ``n x p`` matrix</strong></p>
<blockquote>
<div><p>Represents degrees of freedom</p>
</div></blockquote>
<p><strong>scale_matrix_1: Positive definite matrix</strong></p>
<blockquote>
<div><p>Scale Matrix of shape <code class="docutils literal notranslate"><span class="pre">n</span> <span class="pre">x</span> <span class="pre">n</span></code></p>
</div></blockquote>
<p><strong>scale_matrix_2: Positive definite matrix</strong></p>
<blockquote>
<div><p>Scale Matrix of shape <code class="docutils literal notranslate"><span class="pre">p</span> <span class="pre">x</span> <span class="pre">p</span></code></p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RandomSymbol</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">MatrixNormal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">MatrixNormal</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]],</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">M</span><span class="p">)(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">2*exp(-Trace((Matrix([</span>
<span class="go">[-1],</span>
<span class="go">[-2]]) + X.T)*(Matrix([[-1, -2]]) + X))/2)/pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">M</span><span class="p">)([[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">2*exp(-4)/pi</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r890"><span class="brackets"><a class="fn-backref" href="#id143">R890</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Matrix_normal_distribution">https://en.wikipedia.org/wiki/Matrix_normal_distribution</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="compound-distribution">
<h3>Compound Distribution<a class="headerlink" href="#compound-distribution" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.compound_rv.CompoundDistribution">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.compound_rv.</span></span><span class="sig-name descname"><span class="pre">CompoundDistribution</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dist</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/compound_rv.py#L123-L219"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.compound_rv.CompoundDistribution" title="Permalink to this definition">¶</a></dt>
<dd><p>Class for Compound Distributions.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>dist</strong> : Distribution</p>
<blockquote>
<div><p>Distribution must contain a random parameter</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats.compound_rv</span> <span class="kn">import</span> <span class="n">CompoundDistribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats.crv_types</span> <span class="kn">import</span> <span class="n">NormalDistribution</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">NormalDistribution</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">CompoundDistribution</span><span class="p">(</span><span class="n">N</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">set</span>
<span class="go">Interval(-oo, oo)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">exp(-x**2/64 + x/16 - 1/16)/(8*sqrt(pi))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r891"><span class="brackets"><a class="fn-backref" href="#id144">R891</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Compound_probability_distribution">https://en.wikipedia.org/wiki/Compound_probability_distribution</a></p>
</dd>
</dl>
</dd></dl>

</section>
</section>
<section id="interface">
<h2>Interface<a class="headerlink" href="#interface" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.P">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">P</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">condition</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">given_condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numsamples</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L792-L833"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.P" title="Permalink to this definition">¶</a></dt>
<dd><p>Probability that a condition is true, optionally given a second condition.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>condition</strong> : Combination of Relationals containing RandomSymbols</p>
<blockquote>
<div><p>The condition of which you want to compute the probability</p>
</div></blockquote>
<p><strong>given_condition</strong> : Combination of Relationals containing RandomSymbols</p>
<blockquote>
<div><p>A conditional expression. P(X &gt; 1, X &gt; 0) is expectation of X &gt; 1
given X &gt; 0</p>
</div></blockquote>
<p><strong>numsamples</strong> : int</p>
<blockquote>
<div><p>Enables sampling and approximates the probability with this many samples</p>
</div></blockquote>
<p><strong>evaluate</strong> : Bool (defaults to True)</p>
<blockquote>
<div><p>In case of continuous systems return unevaluated integral</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">P</span><span class="p">,</span> <span class="n">Die</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">1/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">X</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">)</span> <span class="c1"># Probability that X == 5 given that X &gt; 2</span>
<span class="go">1/4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">X</span> <span class="o">&gt;</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">5/12</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.Probability">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Probability</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">prob</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_probability.py#L30-L123"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Probability" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbolic expression for the probability.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Probability</span><span class="p">,</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Integral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">prob</span> <span class="o">=</span> <span class="n">Probability</span><span class="p">(</span><span class="n">X</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">prob</span>
<span class="go">Probability(X &gt; 1)</span>
</pre></div>
</div>
<p>Integral representation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">prob</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Integral</span><span class="p">)</span>
<span class="go">Integral(sqrt(2)*exp(-_z**2/2)/(2*sqrt(pi)), (_z, 1, oo))</span>
</pre></div>
</div>
<p>Evaluation of the integral:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">prob</span><span class="o">.</span><span class="n">evaluate_integral</span><span class="p">()</span>
<span class="go">sqrt(2)*(-sqrt(2)*sqrt(pi)*erf(sqrt(2)/2) + sqrt(2)*sqrt(pi))/(4*sqrt(pi))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.E">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">E</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numsamples</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L751-L789"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.E" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the expected value of a random expression.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr containing RandomSymbols</p>
<blockquote>
<div><p>The expression of which you want to compute the expectation value</p>
</div></blockquote>
<p><strong>given</strong> : Expr containing RandomSymbols</p>
<blockquote>
<div><p>A conditional expression. E(X, X&gt;0) is expectation of X given X &gt; 0</p>
</div></blockquote>
<p><strong>numsamples</strong> : int</p>
<blockquote>
<div><p>Enables sampling and approximates the expectation with this many samples</p>
</div></blockquote>
<p><strong>evalf</strong> : Bool (defaults to True)</p>
<blockquote>
<div><p>If sampling return a number rather than a complex expression</p>
</div></blockquote>
<p><strong>evaluate</strong> : Bool (defaults to True)</p>
<blockquote>
<div><p>In case of continuous systems return unevaluated integral</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">E</span><span class="p">,</span> <span class="n">Die</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">7/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">8</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">)</span> <span class="c1"># Expectation of X given that it is above 3</span>
<span class="go">5</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.Expectation">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Expectation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_probability.py#L126-L315"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Expectation" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbolic expression for the expectation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Expectation</span><span class="p">,</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">Probability</span><span class="p">,</span> <span class="n">Poisson</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Integral</span><span class="p">,</span> <span class="n">Sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;sigma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">Expectation(X)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">evaluate_integral</span><span class="p">()</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">mu</span>
</pre></div>
</div>
<p>To get the integral expression of the expectation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Integral</span><span class="p">)</span>
<span class="go">Integral(sqrt(2)*X*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo))</span>
</pre></div>
</div>
<p>The same integral expression, in more abstract terms:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Probability</span><span class="p">)</span>
<span class="go">Integral(x*Probability(Eq(X, x)), (x, -oo, oo))</span>
</pre></div>
</div>
<p>To get the Summation expression of the expectation for discrete random variables:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">lamda</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;lamda&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">Poisson</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="n">lamda</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">Z</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Sum</span><span class="p">)</span>
<span class="go">Sum(Z*lamda**Z*exp(-lamda)/factorial(Z), (Z, 0, oo))</span>
</pre></div>
</div>
<p>This class is aware of some properties of the expectation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">X</span><span class="p">)</span>
<span class="go">Expectation(a*X)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">Expectation(X + Y)</span>
</pre></div>
</div>
<p>To expand the <code class="docutils literal notranslate"><span class="pre">Expectation</span></code> into its expression, use <code class="docutils literal notranslate"><span class="pre">expand()</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">Expectation(X) + Expectation(Y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">a*Expectation(X) + Expectation(Y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">Expectation(a*X + Y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">((</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">X</span> <span class="o">-</span> <span class="n">Y</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">Expectation(X**2) - Expectation(Y**2)</span>
</pre></div>
</div>
<p>To evaluate the <code class="docutils literal notranslate"><span class="pre">Expectation</span></code>, use <code class="docutils literal notranslate"><span class="pre">doit()</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">mu + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Expectation</span><span class="p">(</span><span class="n">Y</span> <span class="o">+</span> <span class="n">Expectation</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">X</span><span class="p">)))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">3*mu + 1</span>
</pre></div>
</div>
<p>To prevent evaluating nested <code class="docutils literal notranslate"><span class="pre">Expectation</span></code>, use <code class="docutils literal notranslate"><span class="pre">doit(deep=False)</span></code></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Expectation</span><span class="p">(</span><span class="n">Y</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">(</span><span class="n">deep</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">mu + Expectation(Expectation(Y))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Expectation</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Expectation</span><span class="p">(</span><span class="n">Y</span> <span class="o">+</span> <span class="n">Expectation</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">X</span><span class="p">)))</span><span class="o">.</span><span class="n">doit</span><span class="p">(</span><span class="n">deep</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">mu + Expectation(Expectation(Y + Expectation(2*X)))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.density">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">density</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numsamples</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L877-L922"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.density" title="Permalink to this definition">¶</a></dt>
<dd><p>Probability density of a random expression, optionally given a second
condition.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr containing RandomSymbols</p>
<blockquote>
<div><p>The expression of which you want to compute the density value</p>
</div></blockquote>
<p><strong>condition</strong> : Relational containing RandomSymbols</p>
<blockquote>
<div><p>A conditional expression. density(X &gt; 1, X &gt; 0) is density of X &gt; 1
given X &gt; 0</p>
</div></blockquote>
<p><strong>numsamples</strong> : int</p>
<blockquote>
<div><p>Enables sampling and approximates the density with this many samples</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>This density will take on different forms for different types of
probability spaces. Discrete variables produce Dicts. Continuous
variables produce Lambdas.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">density</span><span class="p">,</span> <span class="n">Die</span><span class="p">,</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">D</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{1: 1/6, 2: 1/6, 3: 1/6, 4: 1/6, 5: 1/6, 6: 1/6}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">D</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{2: 1/6, 4: 1/6, 6: 1/6, 8: 1/6, 10: 1/6, 12: 1/6}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">X</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="go">sqrt(2)*exp(-x**2/2)/(2*sqrt(pi))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.entropy">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">entropy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L98-L138"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.entropy" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculuates entropy of a probability distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expression</strong> : the random expression whose entropy is to be calculated</p>
<p><strong>condition</strong> : optional, to specify conditions on random expression</p>
<p><strong>b: base of the logarithm, optional</strong></p>
<blockquote>
<div><p>By default, it is taken as Euler’s number</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>result</strong> : Entropy of the expression, a constant</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">Die</span><span class="p">,</span> <span class="n">entropy</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">entropy</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">log(2)/2 + 1/2 + log(pi)/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">entropy</span><span class="p">(</span><span class="n">D</span><span class="p">)</span>
<span class="go">log(4)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r892"><span class="brackets"><a class="fn-backref" href="#id145">R892</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Entropy_(information_theory">https://en.wikipedia.org/wiki/Entropy_(information_theory</a>)</p>
</dd>
<dt class="label" id="r893"><span class="brackets"><a class="fn-backref" href="#id146">R893</a></span></dt>
<dd><p><a class="reference external" href="https://www.crmarsh.com/static/pdf/Charles_Marsh_Continuous_Entropy.pdf">https://www.crmarsh.com/static/pdf/Charles_Marsh_Continuous_Entropy.pdf</a></p>
</dd>
<dt class="label" id="r894"><span class="brackets"><a class="fn-backref" href="#id147">R894</a></span></dt>
<dd><p><a class="reference external" href="http://www.math.uconn.edu/~kconrad/blurbs/analysis/entropypost.pdf">http://www.math.uconn.edu/~kconrad/blurbs/analysis/entropypost.pdf</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.given">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">given</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L666-L748"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.given" title="Permalink to this definition">¶</a></dt>
<dd><p>Conditional Random Expression.</p>
<p class="rubric">Explanation</p>
<p>From a random expression and a condition on that expression creates a new
probability space from the condition and returns the same expression on that
conditional probability space.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">given</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">Die</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">given</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">density</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">dict</span>
<span class="go">{4: 1/3, 5: 1/3, 6: 1/3}</span>
</pre></div>
</div>
<p>Following convention, if the condition is a random symbol then that symbol
is considered fixed.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pprint</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">z</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">density</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">,</span> <span class="n">Y</span><span class="p">)(</span><span class="n">z</span><span class="p">),</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">                2</span>
<span class="go">       -(-Y + z)</span>
<span class="go">       -----------</span>
<span class="go">  ___       2</span>
<span class="go">\/ 2 *e</span>
<span class="go">------------------</span>
<span class="go">         ____</span>
<span class="go">     2*\/ pi</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.where">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">where</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">condition</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">given_condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L1014-L1042"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.where" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the domain where a condition is True.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">where</span><span class="p">,</span> <span class="n">Die</span><span class="p">,</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">And</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D1</span><span class="p">,</span> <span class="n">D2</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">D1</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="n">D2</span><span class="o">.</span><span class="n">symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">where</span><span class="p">(</span><span class="n">X</span><span class="o">**</span><span class="mi">2</span><span class="o">&lt;</span><span class="mi">1</span><span class="p">)</span>
<span class="go">Domain: (-1 &lt; x) &amp; (x &lt; 1)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">where</span><span class="p">(</span><span class="n">X</span><span class="o">**</span><span class="mi">2</span><span class="o">&lt;</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">set</span>
<span class="go">Interval.open(-1, 1)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">where</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="n">D1</span><span class="o">&lt;=</span><span class="n">D2</span> <span class="p">,</span> <span class="n">D2</span><span class="o">&lt;</span><span class="mi">3</span><span class="p">))</span>
<span class="go">Domain: (Eq(a, 1) &amp; Eq(b, 1)) | (Eq(a, 1) &amp; Eq(b, 2)) | (Eq(a, 2) &amp; Eq(b, 2))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.variance">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">variance</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L46-L73"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.variance" title="Permalink to this definition">¶</a></dt>
<dd><p>Variance of a random expression.</p>
<div class="math notranslate nohighlight">
\[variance(X) = E((X-E(X))^{2})\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Die</span><span class="p">,</span> <span class="n">Bernoulli</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">simplify</span><span class="p">,</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;p&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Bernoulli</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">variance</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">X</span><span class="p">)</span>
<span class="go">35/3</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">variance</span><span class="p">(</span><span class="n">B</span><span class="p">))</span>
<span class="go">p*(1 - p)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.Variance">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Variance</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_probability.py#L317-L427"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Variance" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbolic expression for the variance.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Integral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">Expectation</span><span class="p">,</span> <span class="n">Variance</span><span class="p">,</span> <span class="n">Probability</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;mu&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;sigma&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">Variance(X)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">evaluate_integral</span><span class="p">()</span>
<span class="go">sigma**2</span>
</pre></div>
</div>
<p>Integral representation of the underlying calculations:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Integral</span><span class="p">)</span>
<span class="go">Integral(sqrt(2)*(X - Integral(sqrt(2)*X*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo)))**2*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo))</span>
</pre></div>
</div>
<p>Integral representation, without expanding the PDF:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Probability</span><span class="p">)</span>
<span class="go">-Integral(x*Probability(Eq(X, x)), (x, -oo, oo))**2 + Integral(x**2*Probability(Eq(X, x)), (x, -oo, oo))</span>
</pre></div>
</div>
<p>Rewrite the variance in terms of the expectation</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Expectation</span><span class="p">)</span>
<span class="go">-Expectation(X)**2 + Expectation(X**2)</span>
</pre></div>
</div>
<p>Some transformations based on the properties of the variance may happen:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">X</span><span class="p">)</span>
<span class="go">Variance(a*X)</span>
</pre></div>
</div>
<p>To expand the variance in its expression, use <code class="docutils literal notranslate"><span class="pre">expand()</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">a**2*Variance(X)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">Variance(X + Y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Variance</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">2*Covariance(X, Y) + Variance(X) + Variance(Y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.covariance">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">covariance</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Y</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L140-L176"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.covariance" title="Permalink to this definition">¶</a></dt>
<dd><p>Covariance of two random expressions.</p>
<p class="rubric">Explanation</p>
<p>The expectation that the two variables will rise and fall together</p>
<div class="math notranslate nohighlight">
\[covariance(X,Y) = E((X-E(X)) (Y-E(Y)))\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Exponential</span><span class="p">,</span> <span class="n">covariance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rate</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;lambda&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">finite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">covariance</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span><span class="p">)</span>
<span class="go">lambda**(-2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">covariance</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">covariance</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">+</span> <span class="n">rate</span><span class="o">*</span><span class="n">X</span><span class="p">)</span>
<span class="go">1/lambda</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.Covariance">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Covariance</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_probability.py#L430-L563"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Covariance" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbolic expression for the covariance.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Covariance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;Z&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">W</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;W&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cexpr</span> <span class="o">=</span> <span class="n">Covariance</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cexpr</span>
<span class="go">Covariance(X, Y)</span>
</pre></div>
</div>
<p>Evaluate the covariance, <span class="math notranslate nohighlight">\(X\)</span> and <span class="math notranslate nohighlight">\(Y\)</span> are independent,
therefore zero is the result:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cexpr</span><span class="o">.</span><span class="n">evaluate_integral</span><span class="p">()</span>
<span class="go">0</span>
</pre></div>
</div>
<p>Rewrite the covariance expression in terms of expectations:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Expectation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cexpr</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Expectation</span><span class="p">)</span>
<span class="go">Expectation(X*Y) - Expectation(X)*Expectation(Y)</span>
</pre></div>
</div>
<p>In order to expand the argument, use <code class="docutils literal notranslate"><span class="pre">expand()</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Covariance</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">Y</span><span class="p">,</span> <span class="n">c</span><span class="o">*</span><span class="n">Z</span> <span class="o">+</span> <span class="n">d</span><span class="o">*</span><span class="n">W</span><span class="p">)</span>
<span class="go">Covariance(a*X + b*Y, c*Z + d*W)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Covariance</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">Y</span><span class="p">,</span> <span class="n">c</span><span class="o">*</span><span class="n">Z</span> <span class="o">+</span> <span class="n">d</span><span class="o">*</span><span class="n">W</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">a*c*Covariance(X, Z) + a*d*Covariance(W, X) + b*c*Covariance(Y, Z) + b*d*Covariance(W, Y)</span>
</pre></div>
</div>
<p>This class is aware of some properties of the covariance:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Covariance</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">Variance(X)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Covariance</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">X</span><span class="p">,</span> <span class="n">b</span><span class="o">*</span><span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">a*b*Covariance(X, Y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.coskewness">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">coskewness</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Y</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Z</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L448-L507"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.coskewness" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the co-skewness of three random variables.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>X</strong> : RandomSymbol</p>
<blockquote>
<div><p>Random Variable used to calculate coskewness</p>
</div></blockquote>
<p><strong>Y</strong> : RandomSymbol</p>
<blockquote>
<div><p>Random Variable used to calculate coskewness</p>
</div></blockquote>
<p><strong>Z</strong> : RandomSymbol</p>
<blockquote>
<div><p>Random Variable used to calculate coskewness</p>
</div></blockquote>
<p><strong>condition</strong> : Expr containing RandomSymbols</p>
<blockquote>
<div><p>A conditional expression</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>coskewness</strong> : The coskewness of the three random variables</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>Mathematically Coskewness is defined as</p>
<div class="math notranslate nohighlight">
\[coskewness(X,Y,Z)=\frac{E[(X-E[X]) * (Y-E[Y]) * (Z-E[Z])]} {\sigma_{X}\sigma_{Y}\sigma_{Z}}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">coskewness</span><span class="p">,</span> <span class="n">Exponential</span><span class="p">,</span> <span class="n">skewness</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;p&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">p</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">coskewness</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">coskewness</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">+</span> <span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">X</span><span class="p">)</span>
<span class="go">16*sqrt(85)/85</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">coskewness</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">Y</span><span class="p">,</span> <span class="n">Y</span> <span class="o">+</span> <span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">9*sqrt(170)/85</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">coskewness</span><span class="p">(</span><span class="n">Y</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span> <span class="o">==</span> <span class="n">skewness</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">coskewness</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">+</span> <span class="n">p</span><span class="o">*</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">p</span><span class="o">*</span><span class="n">X</span><span class="p">)</span>
<span class="go">4/(sqrt(1 + 1/(4*p**2))*sqrt(4 + 1/(4*p**2)))</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r895"><span class="brackets"><a class="fn-backref" href="#id148">R895</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Coskewness">https://en.wikipedia.org/wiki/Coskewness</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.median">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">median</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L384-L445"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.median" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculuates the median of the probability distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>X: The random expression whose median is to be calculated.</strong></p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The FiniteSet or an Interval which contains the median of the</p>
<p>random expression.</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>Mathematically, median of Probability distribution is defined as all those
values of <span class="math notranslate nohighlight">\(m\)</span> for which the following condition is satisfied</p>
<div class="math notranslate nohighlight">
\[P(X\leq m) \geq  \frac{1}{2} \text{ and} \text{ } P(X\geq m)\geq \frac{1}{2}\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">Die</span><span class="p">,</span> <span class="n">median</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">median</span><span class="p">(</span><span class="n">N</span><span class="p">)</span>
<span class="go">{3}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">median</span><span class="p">(</span><span class="n">D</span><span class="p">)</span>
<span class="go">{3, 4}</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r896"><span class="brackets"><a class="fn-backref" href="#id149">R896</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Median#Probability_distributions">https://en.wikipedia.org/wiki/Median#Probability_distributions</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.std">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">std</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L76-L95"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.std" title="Permalink to this definition">¶</a></dt>
<dd><p>Standard Deviation of a random expression</p>
<div class="math notranslate nohighlight">
\[std(X) = \sqrt(E((X-E(X))^{2}))\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Bernoulli</span><span class="p">,</span> <span class="n">std</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">simplify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;p&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Bernoulli</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">std</span><span class="p">(</span><span class="n">B</span><span class="p">))</span>
<span class="go">sqrt(p*(1 - p))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.sample">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">sample</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">library</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'scipy'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numsamples</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L1045-L1150"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.sample" title="Permalink to this definition">¶</a></dt>
<dd><p>A realization of the random expression.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expression of random variables</p>
<blockquote>
<div><p>Expression from which sample is extracted</p>
</div></blockquote>
<p><strong>condition</strong> : Expr containing RandomSymbols</p>
<blockquote>
<div><p>A conditional expression</p>
</div></blockquote>
<p><strong>size</strong> : int, tuple</p>
<blockquote>
<div><p>Represents size of each sample in numsamples</p>
</div></blockquote>
<p><strong>library</strong> : str</p>
<blockquote>
<div><ul class="simple">
<li><p>‘scipy’ : Sample using scipy</p></li>
<li><p>‘numpy’ : Sample using numpy</p></li>
<li><p>‘pymc3’ : Sample using PyMC3</p></li>
</ul>
<p>Choose any of the available options to sample from as string,
by default is ‘scipy’</p>
</div></blockquote>
<p><strong>numsamples</strong> : int</p>
<blockquote>
<div><p>Number of samples, each with size as <code class="docutils literal notranslate"><span class="pre">size</span></code>. The <code class="docutils literal notranslate"><span class="pre">numsamples</span></code> parameter is
deprecated and is only provided for compatibility with v1.8. Use a list comprehension
or an additional dimension in <code class="docutils literal notranslate"><span class="pre">size</span></code> instead.</p>
</div></blockquote>
<p><strong>seed :</strong></p>
<blockquote>
<div><p>An object to be used as seed by the given external library for sampling <span class="math notranslate nohighlight">\(expr\)</span>.
Following is the list of possible types of object for the supported libraries,</p>
<ul class="simple">
<li><p>‘scipy’: int, numpy.random.RandomState, numpy.random.Generator</p></li>
<li><p>‘numpy’: int, numpy.random.RandomState, numpy.random.Generator</p></li>
<li><p>‘pymc3’: int</p></li>
</ul>
<p>Optional, by default None, in which case seed settings
related to the given library will be used.
No modifications to environment’s global seed settings
are done by this argument.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>sample: float/list/numpy.ndarray</p>
<blockquote>
<div><p>one sample or a collection of samples of the random expression.</p>
<ul class="simple">
<li><p>sample(X) returns float/numpy.float64/numpy.int64 object.</p></li>
<li><p>sample(X, size=int/tuple) returns numpy.ndarray object.</p></li>
</ul>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Die</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">Geometric</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">Z</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span> <span class="c1"># Finite Random Variable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">die_roll</span> <span class="o">=</span> <span class="n">sample</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span> <span class="o">+</span> <span class="n">Z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">die_roll</span> 
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> <span class="c1"># Continuous Random Variable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp</span> <span class="o">=</span> <span class="n">sample</span><span class="p">(</span><span class="n">N</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp</span> <span class="ow">in</span> <span class="n">N</span><span class="o">.</span><span class="n">pspace</span><span class="o">.</span><span class="n">domain</span><span class="o">.</span><span class="n">set</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp</span> <span class="o">=</span> <span class="n">sample</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">N</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp</span> <span class="o">&gt;</span> <span class="mi">0</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp_list</span> <span class="o">=</span> <span class="n">sample</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">sam</span> <span class="ow">in</span> <span class="n">N</span><span class="o">.</span><span class="n">pspace</span><span class="o">.</span><span class="n">domain</span><span class="o">.</span><span class="n">set</span> <span class="k">for</span> <span class="n">sam</span> <span class="ow">in</span> <span class="n">samp_list</span><span class="p">]</span>
<span class="go">[True, True, True, True]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sample</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">size</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> 
<span class="go">array([[5.42519758, 6.40207856, 4.94991743],</span>
<span class="go">   [1.85819627, 6.83403519, 1.9412172 ]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">Geometric</span><span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)</span> <span class="c1"># Discrete Random Variable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp_list</span> <span class="o">=</span> <span class="n">sample</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp_list</span> 
<span class="go">[1, 3, 2]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">sam</span> <span class="ow">in</span> <span class="n">G</span><span class="o">.</span><span class="n">pspace</span><span class="o">.</span><span class="n">domain</span><span class="o">.</span><span class="n">set</span> <span class="k">for</span> <span class="n">sam</span> <span class="ow">in</span> <span class="n">samp_list</span><span class="p">]</span>
<span class="go">[True, True, True]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MN</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s2">&quot;MN&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span> <span class="c1"># Joint Random Variable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp_list</span> <span class="o">=</span> <span class="n">sample</span><span class="p">(</span><span class="n">MN</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samp_list</span> 
<span class="go">[array([2.85768055, 3.38954165]),</span>
<span class="go"> array([4.11163337, 4.3176591 ]),</span>
<span class="go"> array([0.79115232, 1.63232916]),</span>
<span class="go"> array([4.01747268, 3.96716083])]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="nb">tuple</span><span class="p">(</span><span class="n">sam</span><span class="p">)</span> <span class="ow">in</span> <span class="n">MN</span><span class="o">.</span><span class="n">pspace</span><span class="o">.</span><span class="n">domain</span><span class="o">.</span><span class="n">set</span> <span class="k">for</span> <span class="n">sam</span> <span class="ow">in</span> <span class="n">samp_list</span><span class="p">]</span>
<span class="go">[True, True, True, True]</span>
</pre></div>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 1.7.0: </span>sample used to return an iterator containing the samples instead of value.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 1.9.0: </span>sample returns values or array of values instead of an iterator and numsamples is deprecated.</p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.sample_iter">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">sample_iter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">library</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'scipy'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numsamples</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">oo</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L1202-L1356"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.sample_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an iterator of realizations from the expression given a condition.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr: Expr</strong></p>
<blockquote>
<div><p>Random expression to be realized</p>
</div></blockquote>
<p><strong>condition: Expr, optional</strong></p>
<blockquote>
<div><p>A conditional expression</p>
</div></blockquote>
<p><strong>size</strong> : int, tuple</p>
<blockquote>
<div><p>Represents size of each sample in numsamples</p>
</div></blockquote>
<p><strong>numsamples: integer, optional</strong></p>
<blockquote>
<div><p>Length of the iterator (defaults to infinity)</p>
</div></blockquote>
<p><strong>seed :</strong></p>
<blockquote>
<div><p>An object to be used as seed by the given external library for sampling <span class="math notranslate nohighlight">\(expr\)</span>.
Following is the list of possible types of object for the supported libraries,</p>
<ul class="simple">
<li><p>‘scipy’: int, numpy.random.RandomState, numpy.random.Generator</p></li>
<li><p>‘numpy’: int, numpy.random.RandomState, numpy.random.Generator</p></li>
<li><p>‘pymc3’: int</p></li>
</ul>
<p>Optional, by default None, in which case seed settings
related to the given library will be used.
No modifications to environment’s global seed settings
are done by this argument.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>sample_iter: iterator object</p>
<blockquote>
<div><p>iterator object containing the sample/samples of given expr</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">sample_iter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">X</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="mi">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">iterator</span> <span class="o">=</span> <span class="n">sample_iter</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">numsamples</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> 
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">iterator</span><span class="p">)</span> 
<span class="go">[12, 4, 7]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.sample" title="sympy.stats.sample"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sample</span></code></a>, <a class="reference internal" href="#sympy.stats.rv.sampling_P" title="sympy.stats.rv.sampling_P"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sampling_P</span></code></a>, <a class="reference internal" href="#sympy.stats.rv.sampling_E" title="sympy.stats.rv.sampling_E"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sampling_E</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.factorial_moment">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">factorial_moment</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L345-L382"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.factorial_moment" title="Permalink to this definition">¶</a></dt>
<dd><p>The factorial moment is a mathematical quantity defined as the expectation
or average of the falling factorial of a random variable.</p>
<div class="math notranslate nohighlight">
\[factorial-moment(X, n) = E(X(X - 1)(X - 2)...(X - n + 1))\]</div>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n: A natural number, n-th factorial moment.</strong></p>
<p><strong>condition</strong> : Expr containing RandomSymbols</p>
<blockquote>
<div><p>A conditional expression.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">factorial_moment</span><span class="p">,</span> <span class="n">Poisson</span><span class="p">,</span> <span class="n">Binomial</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lamda</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;lamda&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Poisson</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">lamda</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factorial_moment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">lamda**2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Binomial</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factorial_moment</span><span class="p">(</span><span class="n">Y</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">1/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factorial_moment</span><span class="p">(</span><span class="n">Y</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">Y</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># find factorial moment for Y &gt; 1</span>
<span class="go">2</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r897"><span class="brackets"><a class="fn-backref" href="#id150">R897</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Factorial_moment">https://en.wikipedia.org/wiki/Factorial_moment</a></p>
</dd>
<dt class="label" id="r898"><span class="brackets"><a class="fn-backref" href="#id151">R898</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/FactorialMoment.html">http://mathworld.wolfram.com/FactorialMoment.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.kurtosis">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">kurtosis</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L300-L342"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.kurtosis" title="Permalink to this definition">¶</a></dt>
<dd><p>Characterizes the tails/outliers of a probability distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>condition</strong> : Expr containing RandomSymbols</p>
<blockquote>
<div><p>A conditional expression. kurtosis(X, X&gt;0) is kurtosis of X given X &gt; 0</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>Kurtosis of any univariate normal distribution is 3. Kurtosis less than
3 means that the distribution produces fewer and less extreme outliers
than the normal distribution.</p>
<div class="math notranslate nohighlight">
\[kurtosis(X) = E(((X - E(X))/\sigma_X)^{4})\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">kurtosis</span><span class="p">,</span> <span class="n">Exponential</span><span class="p">,</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">kurtosis</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">kurtosis</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># find kurtosis given X &gt; 0</span>
<span class="go">(-4/pi - 12/pi**2 + 3)/(1 - 2/pi)**2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rate</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;lamda&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">finite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">kurtosis</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span>
<span class="go">9</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r899"><span class="brackets"><a class="fn-backref" href="#id152">R899</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Kurtosis">https://en.wikipedia.org/wiki/Kurtosis</a></p>
</dd>
<dt class="label" id="r900"><span class="brackets"><a class="fn-backref" href="#id153">R900</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/Kurtosis.html">http://mathworld.wolfram.com/Kurtosis.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.skewness">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">skewness</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L263-L298"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.skewness" title="Permalink to this definition">¶</a></dt>
<dd><p>Measure of the asymmetry of the probability distribution.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>condition</strong> : Expr containing RandomSymbols</p>
<blockquote>
<div><p>A conditional expression. skewness(X, X&gt;0) is skewness of X given X &gt; 0</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>Positive skew indicates that most of the values lie to the right of
the mean.</p>
<div class="math notranslate nohighlight">
\[skewness(X) = E(((X - E(X))/\sigma_X)^{3})\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">skewness</span><span class="p">,</span> <span class="n">Exponential</span><span class="p">,</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">skewness</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">skewness</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># find skewness given X &gt; 0</span>
<span class="go">(-sqrt(2)/sqrt(pi) + 4*sqrt(2)/pi**(3/2))/(1 - 2/pi)**(3/2)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rate</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;lambda&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">finite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">skewness</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.correlation">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">correlation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Y</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L179-L211"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.correlation" title="Permalink to this definition">¶</a></dt>
<dd><p>Correlation of two random expressions, also known as correlation
coefficient or Pearson’s correlation.</p>
<p class="rubric">Explanation</p>
<p>The normalized expectation that the two variables will rise
and fall together</p>
<div class="math notranslate nohighlight">
\[correlation(X,Y) = E((X-E(X))(Y-E(Y)) / (\sigma_x  \sigma_y))\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Exponential</span><span class="p">,</span> <span class="n">correlation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rate</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;lambda&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">finite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Exponential</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">correlation</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">X</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">correlation</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">correlation</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">+</span> <span class="n">rate</span><span class="o">*</span><span class="n">X</span><span class="p">)</span>
<span class="go">1/sqrt(1 + lambda**(-2))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.rv.sampling_density">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">sampling_density</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">given_condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">library</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'scipy'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numsamples</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L1424-L1441"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.sampling_density" title="Permalink to this definition">¶</a></dt>
<dd><p>Sampling version of density.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.density" title="sympy.stats.density"><code class="xref py py-obj docutils literal notranslate"><span class="pre">density</span></code></a>, <a class="reference internal" href="#sympy.stats.rv.sampling_P" title="sympy.stats.rv.sampling_P"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sampling_P</span></code></a>, <a class="reference internal" href="#sympy.stats.rv.sampling_E" title="sympy.stats.rv.sampling_E"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sampling_E</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.rv.sampling_P">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">sampling_P</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">condition</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">given_condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">library</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'scipy'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numsamples</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evalf</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L1371-L1400"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.sampling_P" title="Permalink to this definition">¶</a></dt>
<dd><p>Sampling version of P.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.P" title="sympy.stats.P"><code class="xref py py-obj docutils literal notranslate"><span class="pre">P</span></code></a>, <a class="reference internal" href="#sympy.stats.rv.sampling_E" title="sympy.stats.rv.sampling_E"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sampling_E</span></code></a>, <a class="reference internal" href="#sympy.stats.rv.sampling_density" title="sympy.stats.rv.sampling_density"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sampling_density</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.rv.sampling_E">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">sampling_E</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">given_condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">library</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'scipy'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numsamples</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evalf</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L1403-L1422"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.sampling_E" title="Permalink to this definition">¶</a></dt>
<dd><p>Sampling version of E.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.stats.P" title="sympy.stats.P"><code class="xref py py-obj docutils literal notranslate"><span class="pre">P</span></code></a>, <a class="reference internal" href="#sympy.stats.rv.sampling_P" title="sympy.stats.rv.sampling_P"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sampling_P</span></code></a>, <a class="reference internal" href="#sympy.stats.rv.sampling_density" title="sympy.stats.rv.sampling_density"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sampling_density</span></code></a></p>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.Moment">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Moment</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_probability.py#L566-L621"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.Moment" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbolic class for Moment</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Integral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">Expectation</span><span class="p">,</span> <span class="n">Probability</span><span class="p">,</span> <span class="n">Moment</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;mu&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;sigma&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Moment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<p>To evaluate the result of Moment use <span class="math notranslate nohighlight">\(doit\)</span>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">mu**3 - 3*mu**2 + 3*mu*sigma**2 + 3*mu - 3*sigma**2 - 1</span>
</pre></div>
</div>
<p>Rewrite the Moment expression in terms of Expectation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Expectation</span><span class="p">)</span>
<span class="go">Expectation((X - 1)**3)</span>
</pre></div>
</div>
<p>Rewrite the Moment expression in terms of Probability:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Probability</span><span class="p">)</span>
<span class="go">Integral((x - 1)**3*Probability(Eq(X, x)), (x, -oo, oo))</span>
</pre></div>
</div>
<p>Rewrite the Moment expression in terms of Integral:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Integral</span><span class="p">)</span>
<span class="go">Integral(sqrt(2)*(X - 1)**3*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.moment">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">moment</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L19-L43"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.moment" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the nth moment of a random expression about c.</p>
<div class="math notranslate nohighlight">
\[moment(X, c, n) = E((X-c)^{n})\]</div>
<p>Default value of c is 0.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Die</span><span class="p">,</span> <span class="n">moment</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">moment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="go">-5/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">moment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">91/6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">moment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="n">E</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.CentralMoment">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">CentralMoment</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_probability.py#L624-L679"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.CentralMoment" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbolic class Central Moment</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Integral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">Expectation</span><span class="p">,</span> <span class="n">Probability</span><span class="p">,</span> <span class="n">CentralMoment</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;mu&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sigma</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;sigma&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">sigma</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CM</span> <span class="o">=</span> <span class="n">CentralMoment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
</pre></div>
</div>
<p>To evaluate the result of CentralMoment use <span class="math notranslate nohighlight">\(doit\)</span>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">CM</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">3*sigma**4</span>
</pre></div>
</div>
<p>Rewrite the CentralMoment expression in terms of Expectation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">CM</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Expectation</span><span class="p">)</span>
<span class="go">Expectation((X - Expectation(X))**4)</span>
</pre></div>
</div>
<p>Rewrite the CentralMoment expression in terms of Probability:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">CM</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Probability</span><span class="p">)</span>
<span class="go">Integral((x - Integral(x*Probability(True), (x, -oo, oo)))**4*Probability(Eq(X, x)), (x, -oo, oo))</span>
</pre></div>
</div>
<p>Rewrite the CentralMoment expression in terms of Integral:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">CM</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">Integral</span><span class="p">)</span>
<span class="go">Integral(sqrt(2)*(X - Integral(sqrt(2)*X*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo)))**4*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.cmoment">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">cmoment</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv_interface.py#L214-L236"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.cmoment" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the nth central moment of a random expression about its mean.</p>
<div class="math notranslate nohighlight">
\[cmoment(X, n) = E((X - E(X))^{n})\]</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">Die</span><span class="p">,</span> <span class="n">cmoment</span><span class="p">,</span> <span class="n">variance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Die</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cmoment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cmoment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">35/12</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cmoment</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="n">variance</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.ExpectationMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">ExpectationMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_multivariate_probability.py#L10-L107"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.ExpectationMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Expectation of a random matrix expression.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">ExpectationMatrix</span><span class="p">,</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats.rv</span> <span class="kn">import</span> <span class="n">RandomMatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">=</span> <span class="n">RandomMatrixSymbol</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">RandomMatrixSymbol</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ExpectationMatrix</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">ExpectationMatrix(X)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ExpectationMatrix</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(k, 1)</span>
</pre></div>
</div>
<p>To expand the expectation in its expression, use <code class="docutils literal notranslate"><span class="pre">expand()</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ExpectationMatrix</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="n">B</span><span class="o">*</span><span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">A*ExpectationMatrix(X) + B*ExpectationMatrix(Y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ExpectationMatrix</span><span class="p">((</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">X</span> <span class="o">-</span> <span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">ExpectationMatrix(X*X.T) - ExpectationMatrix(X*Y.T) + ExpectationMatrix(Y*X.T) - ExpectationMatrix(Y*Y.T)</span>
</pre></div>
</div>
<p>To evaluate the <code class="docutils literal notranslate"><span class="pre">ExpectationMatrix</span></code>, use <code class="docutils literal notranslate"><span class="pre">doit()</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">N11</span><span class="p">,</span> <span class="n">N12</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;N11&#39;</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;N12&#39;</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N21</span><span class="p">,</span> <span class="n">N22</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;N21&#39;</span><span class="p">,</span> <span class="mi">21</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;N22&#39;</span><span class="p">,</span> <span class="mi">22</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M11</span><span class="p">,</span> <span class="n">M12</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;M11&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;M12&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M21</span><span class="p">,</span> <span class="n">M22</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;M21&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;M22&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x1</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">N11</span><span class="p">,</span> <span class="n">N12</span><span class="p">],</span> <span class="p">[</span><span class="n">N21</span><span class="p">,</span> <span class="n">N22</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x2</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">M11</span><span class="p">,</span> <span class="n">M12</span><span class="p">],</span> <span class="p">[</span><span class="n">M21</span><span class="p">,</span> <span class="n">M22</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ExpectationMatrix</span><span class="p">(</span><span class="n">x1</span> <span class="o">+</span> <span class="n">x2</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[12, 14],</span>
<span class="go">[24, 26]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.VarianceMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">VarianceMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_multivariate_probability.py#L109-L195"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.VarianceMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Variance of a random matrix probability expression. Also known as
Covariance matrix, auto-covariance matrix, dispersion matrix,
or variance-covariance matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">VarianceMatrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats.rv</span> <span class="kn">import</span> <span class="n">RandomMatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">=</span> <span class="n">RandomMatrixSymbol</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">RandomMatrixSymbol</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">VarianceMatrix</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">VarianceMatrix(X)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">VarianceMatrix</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(k, k)</span>
</pre></div>
</div>
<p>To expand the variance in its expression, use <code class="docutils literal notranslate"><span class="pre">expand()</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">VarianceMatrix</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">A*VarianceMatrix(X)*A.T</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">VarianceMatrix</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="n">B</span><span class="o">*</span><span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">2*A*CrossCovarianceMatrix(X, Y)*B.T + A*VarianceMatrix(X)*A.T + B*VarianceMatrix(Y)*B.T</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.CrossCovarianceMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">CrossCovarianceMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">condition</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/symbolic_multivariate_probability.py#L197-L301"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.CrossCovarianceMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Covariance of a random matrix probability expression.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">CrossCovarianceMatrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats.rv</span> <span class="kn">import</span> <span class="n">RandomMatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;k&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="p">,</span> <span class="n">D</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;D&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">=</span> <span class="n">RandomMatrixSymbol</span><span class="p">(</span><span class="s2">&quot;X&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">RandomMatrixSymbol</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span><span class="p">,</span> <span class="n">W</span> <span class="o">=</span> <span class="n">RandomMatrixSymbol</span><span class="p">(</span><span class="s2">&quot;Z&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">RandomMatrixSymbol</span><span class="p">(</span><span class="s2">&quot;W&quot;</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CrossCovarianceMatrix</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">CrossCovarianceMatrix(X, Y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CrossCovarianceMatrix</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(k, k)</span>
</pre></div>
</div>
<p>To expand the covariance in its expression, use <code class="docutils literal notranslate"><span class="pre">expand()</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">CrossCovarianceMatrix</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="n">Y</span><span class="p">,</span> <span class="n">Z</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">CrossCovarianceMatrix(X, Z) + CrossCovarianceMatrix(Y, Z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CrossCovarianceMatrix</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">X</span> <span class="p">,</span> <span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">A*CrossCovarianceMatrix(X, Y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CrossCovarianceMatrix</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">X</span><span class="p">,</span> <span class="n">B</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">Y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">A*CrossCovarianceMatrix(X, Y)*B</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CrossCovarianceMatrix</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="n">B</span><span class="o">*</span><span class="n">Y</span><span class="p">,</span> <span class="n">C</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">Z</span> <span class="o">+</span> <span class="n">D</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">W</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">A*CrossCovarianceMatrix(X, W)*D + A*CrossCovarianceMatrix(X, Z)*C + B*CrossCovarianceMatrix(Y, W)*D + B*CrossCovarianceMatrix(Y, Z)*C</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.stats.rv">
<span id="mechanics"></span><h2>Mechanics<a class="headerlink" href="#module-sympy.stats.rv" title="Permalink to this headline">¶</a></h2>
<p>SymPy Stats employs a relatively complex class hierarchy.</p>
<p><code class="docutils literal notranslate"><span class="pre">RandomDomain</span></code>s are a mapping of variables to possible values.
For example, we might say that the symbol <code class="docutils literal notranslate"><span class="pre">Symbol('x')</span></code> can
take on the values <span class="math notranslate nohighlight">\(\{1,2,3,4,5,6\}\)</span>.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.rv.RandomDomain">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">RandomDomain</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L45-L77"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.RandomDomain" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>A <code class="docutils literal notranslate"><span class="pre">PSpace</span></code>, or Probability Space, combines a <code class="docutils literal notranslate"><span class="pre">RandomDomain</span></code>
with a density to provide probabilistic information. For example
the above domain could be enhanced by a finite density
<code class="docutils literal notranslate"><span class="pre">{1:1/6,</span> <span class="pre">2:1/6,</span> <span class="pre">3:1/6,</span> <span class="pre">4:1/6,</span> <span class="pre">5:1/6,</span> <span class="pre">6:1/6}</span></code> to
fully define the roll of a fair die named <code class="docutils literal notranslate"><span class="pre">x</span></code>.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.rv.PSpace">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">PSpace</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L162-L214"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.PSpace" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>A RandomSymbol represents the PSpace’s symbol ‘x’ inside of SymPy expressions.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.rv.RandomSymbol">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">RandomSymbol</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L243-L309"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.RandomSymbol" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The RandomDomain and PSpace classes are almost never directly instantiated.
Instead they are subclassed for a variety of situations.</p>
<p>RandomDomains and PSpaces must be sufficiently general to represent domains and
spaces of several variables with arbitrarily complex densities. This generality
is often unnecessary. Instead we often build SingleDomains and SinglePSpaces to
represent single, univariate events and processes such as a single die or a
single normal variable.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.rv.SinglePSpace">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">SinglePSpace</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L217-L240"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.SinglePSpace" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.rv.SingleDomain">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">SingleDomain</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L80-L106"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.SingleDomain" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Another common case is to collect together a set of such univariate random
variables. A collection of independent SinglePSpaces or SingleDomains can be
brought together to form a ProductDomain or ProductPSpace. These objects would
be useful in representing three dice rolled together for example.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.rv.ProductDomain">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">ProductDomain</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L523-L588"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.ProductDomain" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.rv.ProductPSpace">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">ProductPSpace</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L356-L367"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.ProductPSpace" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The Conditional adjective is added whenever we add a global condition to a
RandomDomain or PSpace. A common example would be three independent dice where
we know their sum to be greater than 12.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.rv.ConditionalDomain">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">ConditionalDomain</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L127-L159"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.ConditionalDomain" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>We specialize further into Finite and Continuous versions of these classes to
represent finite (such as dice) and continuous (such as normals) random
variables.</p>
<span class="target" id="module-sympy.stats.frv"></span><dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.frv.FiniteDomain">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.frv.</span></span><span class="sig-name descname"><span class="pre">FiniteDomain</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv.py#L50-L77"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.frv.FiniteDomain" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.frv.FinitePSpace">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.frv.</span></span><span class="sig-name descname"><span class="pre">FinitePSpace</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/frv.py#L223-L344"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.frv.FinitePSpace" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<span class="target" id="module-sympy.stats.crv"></span><dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.crv.ContinuousDomain">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.crv.</span></span><span class="sig-name descname"><span class="pre">ContinuousDomain</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv.py#L25-L34"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.crv.ContinuousDomain" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.crv.ContinuousPSpace">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.crv.</span></span><span class="sig-name descname"><span class="pre">ContinuousPSpace</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/crv.py#L294-L451"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.crv.ContinuousPSpace" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Additionally there are a few specialized classes that implement certain common
random variable types. There is for example a DiePSpace that implements
SingleFinitePSpace and a NormalPSpace that implements SingleContinuousPSpace.</p>
<span class="target" id="module-sympy.stats.frv_types"></span><dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.frv_types.DiePSpace">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.frv_types.</span></span><span class="sig-name descname"><span class="pre">DiePSpace</span></span><a class="headerlink" href="#sympy.stats.frv_types.DiePSpace" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<span class="target" id="module-sympy.stats.crv_types"></span><dl class="py class">
<dt class="sig sig-object py" id="sympy.stats.crv_types.NormalPSpace">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.stats.crv_types.</span></span><span class="sig-name descname"><span class="pre">NormalPSpace</span></span><a class="headerlink" href="#sympy.stats.crv_types.NormalPSpace" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>RandomVariables can be extracted from these objects using the PSpace.values
method.</p>
<p>As previously mentioned SymPy Stats employs a relatively complex class
structure. Inheritance is widely used in the implementation of end-level
classes. This tactic was chosen to balance between the need to allow SymPy to
represent arbitrarily defined random variables and optimizing for common cases.
This complicates the code but is structured to only be important to those
working on extending SymPy Stats to other random variable types.</p>
<p>Users will not use this class structure. Instead these mechanics are exposed
through variable creation functions Die, Coin, FiniteRV, Normal, Exponential,
etc…. These build the appropriate SinglePSpaces and return the corresponding
RandomVariable. Conditional and Product spaces are formed in the natural
construction of SymPy expressions and the use of interface functions E, Given,
Density, etc….</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.crv_types.sympy.stats.Die">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Die</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sympy.stats.crv_types.sympy.stats.Die" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.crv_types.sympy.stats.Normal">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.</span></span><span class="sig-name descname"><span class="pre">Normal</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sympy.stats.crv_types.sympy.stats.Normal" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>There are some additional functions that may be useful. They are largely used
internally.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.rv.random_symbols">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">random_symbols</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L591-L601"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.random_symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns all RandomSymbols within a SymPy Expression.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.rv.pspace">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">pspace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L604-L637"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.pspace" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the underlying Probability Space of a random expression.</p>
<p>For internal use.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.stats</span> <span class="kn">import</span> <span class="n">pspace</span><span class="p">,</span> <span class="n">Normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Normal</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pspace</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">X</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="n">X</span><span class="o">.</span><span class="n">pspace</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.stats.rv.rs_swap">
<span class="sig-prename descclassname"><span class="pre">sympy.stats.rv.</span></span><span class="sig-name descname"><span class="pre">rs_swap</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/stats/rv.py#L647-L663"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.stats.rv.rs_swap" title="Permalink to this definition">¶</a></dt>
<dd><p>Build a dictionary to swap RandomSymbols based on their underlying symbol.</p>
<p>i.e.
if    <code class="docutils literal notranslate"><span class="pre">X</span> <span class="pre">=</span> <span class="pre">('x',</span> <span class="pre">pspace1)</span></code>
and   <code class="docutils literal notranslate"><span class="pre">Y</span> <span class="pre">=</span> <span class="pre">('x',</span> <span class="pre">pspace2)</span></code>
then <code class="docutils literal notranslate"><span class="pre">X</span></code> and <code class="docutils literal notranslate"><span class="pre">Y</span></code> match and the key, value pair
<code class="docutils literal notranslate"><span class="pre">{X:Y}</span></code> will appear in the result</p>
<p>Inputs: collections a and b of random variables which share common symbols
Output: dict mapping RVs in a to RVs in b</p>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Stats</a><ul>
<li><a class="reference internal" href="#examples">Examples</a></li>
<li><a class="reference internal" href="#random-variable-types">Random Variable Types</a><ul>
<li><a class="reference internal" href="#finite-types">Finite Types</a></li>
<li><a class="reference internal" href="#discrete-types">Discrete Types</a></li>
<li><a class="reference internal" href="#continuous-types">Continuous Types</a></li>
<li><a class="reference internal" href="#joint-types">Joint Types</a></li>
<li><a class="reference internal" href="#stochastic-processes">Stochastic Processes</a></li>
<li><a class="reference internal" href="#matrix-distributions">Matrix Distributions</a></li>
<li><a class="reference internal" href="#compound-distribution">Compound Distribution</a></li>
</ul>
</li>
<li><a class="reference internal" href="#interface">Interface</a></li>
<li><a class="reference internal" href="#module-sympy.stats.rv">Mechanics</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="solvers/solveset.html"
                        title="previous chapter">Solveset</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="tensor/index.html"
                        title="next chapter">Tensor</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/modules/stats.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tensor/index.html" title="Tensor"
             >next</a> |</li>
        <li class="right" >
          <a href="solvers/solveset.html" title="Solveset"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Stats</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/stats.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:25:50 GMT -->
</html>